(Java) Blowfish Encryption, ECB, CBC, CFB modes. Blowfish encryption. The Chilkat encryption component supports Blowfish key sizes ranging from 32-bits to 448-bits. Chilkat's blowfish implementation supports ECB (Electronic Cookbook), CBC (Cipher-Block Chaining), and CFB (Cipher Feedback) modes.
1. Intel basedDesktop PC: - RAM of 512 MB
3. IntelliJ IDEACommunity Edition
THEORY:
ØBlowfish isalso an encryption technique which is replacement to DES algorithm and that is very powerful ammunition against hackers andcyber-criminals. It is utilized in a wide array of products like inperformance-constrained environments such as embedded systems, secure E-mailencryption tools, backup software, password management tools.
ØItis a symmetric key encryption algorithm in which the same secret key isused for both encryption and decryption i.e. same secret key is used by senderand receiver and it is kept secret.
ØItis block cipher algorithm i.e. The message is divided into fixed length blocks(64-bits) during encryption and decryption. The key size ranges from 32 to 448bits(variable length key is used)
ØItis compact i.e. executes in less memory and simple (XOR, Addition etcoperations are performed here) algorithm.
ØItis a 16-round Feistel cipher and uses large key-dependent Substitution-boxes(S-Box)
SOURCECODE:
import java.io.FileInputStream; import java.io.FileOutputStream; import java.security.Key; import java.util.Base64; import javax.crypto.Cipher; import javax.crypto.CipherOutputStream; import javax.crypto.KeyGenerator; ![]() public class BlowFish { public static void main(String[] args) throws Exception { KeyGenerator keyGenerator= KeyGenerator.getInstance('Blowfish'); keyGenerator.init(128); Key secretKey = keyGenerator.generateKey(); Cipher cipherOut = Cipher.getInstance('Blowfish/CFB/NoPadding'); cipherOut.init(Cipher.ENCRYPT_MODE,secretKey); Base64.Encoder encoder = Base64.getEncoder(); byte iv[] = cipherOut.getIV(); if(iv!=null){ System.out.println('Initialization vector of the Cipher:' + encoder.encodeToString(iv)); } FileInputStream fin = new FileInputStream('inputFile.txt'); FileOutputStream fout = new FileOutputStream('outputFile.txt'); CipherOutputStream cout = new CipherOutputStream(fout,cipherOut); int input; while((input = fin.read()) != -1) { cout.write(input); ![]() } fin.close(); cout.close(); } }
This inputFile should be stored in the same folder whereBlowFish.java file is kept
A Simple Blowfish Encryption / Decryption using Java
This is a simple encryption using Blowfish Algorithm that i use to encrypt several properties on my application. On this example im using username appended with password as salt to encrypt password variables.
Related PostsBudi Oktaviyanabout 6 years ago
Just another way bro :D
public class BlowfishTest { public static final String BLOWFISH = 'Blowfish'; public static String x; public static void main(String[] args) throws Exception { encrypt('geriii','p@ssw0rd'); decrypt('HDXiT9dQeGXUsX8hoWNH5w'); } public static void encrypt(String username, String password) throws Exception { x = new StringBuilder(username).append(password).toString(); byte[] keyData = (x).getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyData, BLOWFISH); Cipher cipher = Cipher.getInstance(BLOWFISH); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); byte[] result = cipher.doFinal(password.getBytes()); System.out.println(new BASE64Encoder().encode(result)); } public static void decrypt(String param) throws Exception { byte[] keyData = (x).getBytes(); SecretKeySpec secretKeySpec = new SecretKeySpec(keyData, BLOWFISH); Cipher cipher = Cipher.getInstance(BLOWFISH); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); byte[] result = cipher.doFinal(new BASE64Decoder().decodeBuffer(param)); System.out.println(new String(result)); } }
[email protected]about 3 years ago
I'm not Java programmer, and I'm trying to make this implementation. I know it's been four years, but I can not help noticing that the decript function requires the encrypted text size (which will not have) ..
Leave a CommentComments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |