BlowFish - Program
BlowFish - Program
EXPERIMENT – 5:
Write a C/JAVA program to implement the Blowfish algorithm logic.
PROGRAM:
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
/**
* This program demonstrates how to encrypt/decrypt
* input using the Blowfish
* Cipher with the Java Cryptography.
*/
public class BlowfishDemo
NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException,UnsupportedEncodingException
JNTUH (R-18)
Cryptography & Network Security Lab MRIET
cipher.init(Cipher.ENCRYPT_MODE, KS);
String encryptedtext =
Base64.getEncoder().encodeToString(cipher.doFinal(password.getBytes("UTF-
8")));
return encryptedtext;
InvalidKeyException, IllegalBlockSizeException,
BadPaddingException
byte[] ecryptedtexttobytes =
Base64.getDecoder().decode(encryptedtext);
cipher.init(Cipher.DECRYPT_MODE, KS);
return decryptedString;
JNTUH (R-18)
Cryptography & Network Security Lab MRIET
OUTPUT:
Password: BlowFish@123
JNTUH (R-18)