0% found this document useful (0 votes)
12 views

Program To Implement Blowfish Algorithm Logic

Uploaded by

Subbu Kuricheti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Program To Implement Blowfish Algorithm Logic

Uploaded by

Subbu Kuricheti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5.

Program to implement BlowFish algorithm logic

import java.io.*;
import java.security.Key;
import javax.crypto.*;
import javax.crypto.CipherOutputStream;
import java.util.Base64;
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();
}
}
OUTPUT:

This inputFile.txt should be stored in the same folder where BlowFish.java file kept.

You might also like