vicker313 tech blog

February 28, 2010

How to Allow Access of Internal Class in Another .Net Assembly

Filed under: .Net — Tags: , , , — vicker313 @ 8:00 am

We always create separate assemblies so that we can reuse some of the classes, and declare the classes as public so that can be accessed by other assemblies. However this will allow other people to use the assemblies that we created. To protect our assemblies to be assessed by our owned assemblies only, we can declare the classes as internal and do the following setup:

For the assembly that will access your shared assembly

  1. Use SN utility to create a new key pair and save it in an out put file (key.snk). SN is available in .Net SDK.
    sn -k key.snk
  2. Use your .Net IDE (either Visual Studio or Sharpdevelop) to sign the assembly with the key file (key.snk).
  3. Compile the assembly.
  4. Use SECUTIL to extract the strong name information from the assembly (usually in the bin\debug directory in you project folder) in hex string format and save it to a text file (strong.txt). SECUTIL is also available in .Net SDK.
    secutil -hex -s application.exe > strong.txt
  5. Inside the strong name file (strong.txt), you can see a long hex string, copy it (remember to exclude the first 2 character 0x)

For the shared assembly

  1. Use SN utility to create a another key pair and save it in an out put file (key1.snk).
    sn -k key1.snk
  2. Use your .Net IDE (either Visual Studio or Sharpdevelop) to sign the assembly with the key file (key1.snk).
  3. Open AssemblyInfo.cs, (or AssemblyInfo.vb, depend on the language that you used)
  4. Be sure System.Runtime.Compiler.Services is imported:
    using System.Runtime.CompilerServices;
  5. Go to last line of the file, add the following line (ProgramName is the name of you referring assembly and hexstring is the hex string that you copied from the strong name file just now)
    [assembly: InternalsVisibleTo("ProgramName, PublicKey=hexstring")]
  6. Compile the assembly.

Now you should able to refer the shared assembly and use the internal classes.

You might not need to install SDK to get SN or SECUTIL, try google around should able to find some download links.

February 21, 2010

Another Management Tool for Firebird, and Other DB…

Filed under: Firebird — Tags: , , , , , — vicker313 @ 9:39 am

I have recommend Flamerobin as Firebird Management Tool in my earlier post, because it is free and light weighted. Recently I found another tool called EMS SQL Manager for InterBase/Firebird. It is a commercial software which has a free version. The free version does not have an expire date, but it will have a splash screen that halt the program for a while during start up. However I do believe the wait is worth because it has a bunch of features that every developer want.

To use EMS SQL Manager (I download the stand alone version, which no need for installation), you will need Firebird Access Library that within Firebird binary folder. Depend on what type of server you want to connect, for server based Firebird, you need to configure the Manager where fbclient.dll located. And for embedded Firebird, you need to locate where is fbembed.dll.

Other than Firebird, there are tools for other database such as:

  1. EMS SQL Manager for MySQL
  2. EMS SQL Manager for MSSQL
  3. EMS SQL Manager for Oracle

February 14, 2010

Redirect from HTTP to HTTPS in Tomcat

Filed under: Tomcat — Tags: , , , — vicker313 @ 9:09 am

Simple method to configure Tomcat (the version I try is Tomcat 6) so that all HTTP access will redirect to HTTPS.

Edit [TOMCAT_HOME]\webapps\ROOT\WEB-INF\web.xml, add the following codes inside the web-app tag (or just the above of </web-app>).
<security-constraint>
<web-resource-collection>
<web-resource-name>Automatic SSL Forwarding</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

February 7, 2010

CPIO Tape with Unknown Block Size

Filed under: Linux — Tags: , , — vicker313 @ 11:09 am

Here are same useful CPIO command samples (assume the tape is /dev/st0):

  1. To list out the content of the tape:
    cpio -tv -F /dev/st0
  2. To extract the tape to working directory:
    cpio -iv -F /dev/st0
  3. To archive files from working directory to tape:
    find . -print | cpio -ov -F /dev/st0

Sometime we might face problem in extracting the tape because wrong block size is used. To check the block size used in a CPIO archived tape catridges, try command below:

dd if=/dev/sto of=/tmp/deleteme ibs=64k count=1

If no error prompts out, it means the tape is archived in 64k. Else try other block size number such as 128k until you find a figure that doesn’t result an error message. The command will create a dummy file called deleteme at /tmp, which can safely be removed. After you know the block size, use command below to list or extract the content of the tape:

cpio -tv --block-size 64 -F /dev/st0

cpio -iv --block-size 64 -F /dev/st0

Create a free website or blog at WordPress.com.