Click here to Skip to main content
15,867,568 members
Articles / Security / Encryption
Tip/Trick

Blowfish Encryption Implementation in .NET

Rate me:
Please Sign up or sign in to vote.
4.82/5 (15 votes)
21 May 2012CPOL 119.1K   22   31
Blowfish encryption is very popular for encrypting data but its really hard to find a simple .net implementation of this algorithm. This articles tries to solve this problem.

Recently, while working on a project we needed a component in .Net which can encrypt/decrypt user password using Blowfish algorithm with a encryption key. We searched hard to get a ready made free .Net component to accomplish this task but found none! Finally we found a implementation hint from a article posted on igniterealtime. We took the blowfish.java file from Spark IM project and ported it to a .NET dll using ikvm, a jvm for .Net. We then referenced the dlls and used the encrypt and decrypt methods to do the required tasks.

 
Its very easy to implement this algorithm using attached Dlls. Download the zip file which contains three dlls - 'Blowfish.dll', 'IKVM.OpenJDK.Core.dll', and 'IKVM.Runtime.dll'. Add reference to these three dlls in your project.
 
Declare the namespace on the top of the class file:
C#
using org.jivesoftware.util;
Next, declare an instance of the Blowfish class:
C#
Blowfish algo = new Blowfish(encryptionKey);
Next, call the appropriate method to encrypt/decrypt the text:
C#
string encryptedTxt = algo.encryptString("this is my test string");
string decryptedTxt = algo.decryptString(encryptedTxt);
Thats it! Thats all that we have to do to implement this algorithm.
 
History - First publish - 03 Aug 2011.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager Brand Recourse Technologies
India India
Ravinder is an experienced software developer and project manager having around 12+ years of experience in Project management and software development field. He has done Bachelor of Engineering and Post Graduate Diploma with Information Technology as major. He is PMP certified professional from PMI, USA. He likes to code in .Net specifically for window based applications. Currently he is associated with Brand Recourse Technologies, Noida, India as Chief Technology Officer.

Comments and Discussions

 
GeneralMy vote of 1 Pin
jim something or other21-Jan-16 1:17
jim something or other21-Jan-16 1:17 
QuestionInitialization Vector Pin
BlueFish10121-Jul-15 7:09
BlueFish10121-Jul-15 7:09 
AnswerRe: Initialization Vector Pin
Ravinder Singh Yadav21-Jul-15 7:24
Ravinder Singh Yadav21-Jul-15 7:24 
GeneralRe: Initialization Vector Pin
BlueFish10121-Jul-15 8:52
BlueFish10121-Jul-15 8:52 
GeneralRe: Initialization Vector Pin
BlueFish10121-Jul-15 9:06
BlueFish10121-Jul-15 9:06 
GeneralRe: Initialization Vector Pin
BlueFish10123-Jul-15 13:21
BlueFish10123-Jul-15 13:21 
GeneralRe: Initialization Vector Pin
Ravinder Singh Yadav24-Jul-15 7:03
Ravinder Singh Yadav24-Jul-15 7:03 
Questiondear sir, have you tried to encrypt a text file using blowfish ? Pin
zhangdf1129-Apr-14 6:56
zhangdf1129-Apr-14 6:56 
AnswerRe: dear sir, have you tried to encrypt a text file using blowfish ? Pin
Ravinder Singh Yadav30-Apr-14 7:46
Ravinder Singh Yadav30-Apr-14 7:46 
GeneralRe: dear sir, have you tried to encrypt a text file using blowfish ? Pin
zhangdf1130-Apr-14 16:07
zhangdf1130-Apr-14 16:07 
Questioni got an error Pin
sangerie26-Dec-13 19:44
sangerie26-Dec-13 19:44 
QuestionError on using Pin
raoulFR10-Dec-13 4:22
professionalraoulFR10-Dec-13 4:22 
AnswerRe: Error on using Pin
Ravinder Singh Yadav10-Dec-13 6:10
Ravinder Singh Yadav10-Dec-13 6:10 
GeneralRe: Error on using Pin
raoulFR10-Dec-13 7:38
professionalraoulFR10-Dec-13 7:38 
GeneralMy Vote 5 stars Pin
veski4a9216-Oct-13 22:02
veski4a9216-Oct-13 22:02 
Questionproblem Pin
creativemujahid28-Apr-13 22:35
creativemujahid28-Apr-13 22:35 
AnswerRe: problem Pin
Ravinder Singh Yadav1-May-13 19:00
Ravinder Singh Yadav1-May-13 19:00 
Questionhaving trouble Pin
Alvaro3197-Jan-13 9:24
Alvaro3197-Jan-13 9:24 
QuestionThank you so much ! Pin
Samanph11-Sep-12 5:11
Samanph11-Sep-12 5:11 
AnswerRe: Thank you so much ! Pin
Ravinder Singh Yadav11-Sep-12 6:30
Ravinder Singh Yadav11-Sep-12 6:30 
QuestionBlowfish output Pin
rautyog22-Jun-12 2:09
rautyog22-Jun-12 2:09 
AnswerRe: Blowfish output Pin
Ravinder Singh Yadav22-Jun-12 8:05
Ravinder Singh Yadav22-Jun-12 8:05 
Questionnot found the page Pin
Grenseal20-May-12 21:17
Grenseal20-May-12 21:17 
AnswerRe: not found the page Pin
Ravinder Singh Yadav21-May-12 5:39
Ravinder Singh Yadav21-May-12 5:39 
GeneralRe: not found the page Pin
Grenseal21-May-12 17:15
Grenseal21-May-12 17:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.