Wednesday, May 20, 2009

bqWchpa2JMtot1CZCli8ZhLh0yUb1GU9

Once I completed my B. Sc in Computer Science and Engineering course, I listed a set of subjects that I would never use. All the Electrical, Electronic, Mechanical, Civil and Material Engineering subject were among them. Further, I included Bio informatics, Computer security and Compiler Theory courses, which belong to my major stream .Then I removed the learning materials of those subjects. However, my decision was wrong; I would not have removed Computer Security materials. Okay, lets get in to the topic.

As Wiki says,Blowfish is a
>> Keyed ( Key is the parameter that is used to determine the output of a cryptographic algorithm or cipher ),
>> Symmetric ( The same key is used for both encryption and decryption ),
>> Block cipher (operates on fixed-length groups of bits,)
,
designed in 1993 by Bruce Schneier. You can find more details from Wiki , so I do not repeat Key Encryption, Encryption, and Decryption details.

I have found two java implementations of Blowfish,

1.Java 2 Platform SE v1.4.2, javax.crypto package
2.GNU blowfish implementation

I have developed a sample application that you can simply start with using 1st implementation. This can be used to encrypt a string using a key (length <=128). The BlowfishEncryptor class API is as follows

/**
* Generates a secret key for a given key size and store in a file. This is
* used only once.
* @param keySize
* Size of the key
* @param fileName
* File name that needs to be stored
*/
public void generateKey(int keySize, String fileName)

/**
* Takes a single String as an argument and returns an Encrypted version of
* that String.
* @param str
* String to be encrypted
* @return String Encrypted version of the provided String
*/
public String encrypt(String str)

/**
* Initializing this object's encrypter and decrypter
* Chipher instances given a secret key file name.
* @param keyFileName
* Secret Key used to identify the key file
*/
public void init(String keyFileName)

/**
* Takes a encrypted String as an argument, decrypts and returns the
* decrypted String.
* @param str
* Encrypted String to be decrypted
* @return String Decrypted version of the provided String
*/
public String decrypt(String str)

The eclipse project is here. I have included a sample Main class to this project as well. To get the topic of this post, copy the current topic and decrypt it using “testKey2” file. Enjoy it :).

2 comments: