Implementing BlowFish Algorithm:
Code:import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class BlowFishCipher
{
public static void main(String[] args)throws Exception
{
KeyGenerator keygen=KeyGenerator.getInstance("Blowfish");
SecretKey sk=keygen.generateKey();
Cipher cip=Cipher.getInstance("Blowfish");
cip.init(Cipher.ENCRYPT_MODE,sk);
String inputText="Hello";
byte[] encrypted=cip.doFinal(inputText.getBytes());
System.out.println("Encrypted :"+new String(encrypted));
cip.init(Cipher.DECRYPT_MODE,sk);
byte[] decrypted=cip.doFinal(encrypted);
System.out.println("Decrypted :"+new String(decrypted));
System.exit(0);
}
}
If the answers is incorrect or not given, you can answer the above question in the comment box. If the answers is incorrect or not given, you can answer the above question in the comment box.