Write a JAVA program to implement the BlowFish algorithm | BlowFish algorithm in JAVA | Cryptography


HARDWARE AND SOFTWARE REQUIREMENT:
1. Intel based Desktop PC: - RAM of 512 MB
2. Notepad/Notepad ++ editor  and Command Prompt or
3. IntelliJ IDEA Community Edition

THEORY:

Ø  Blowfish is also an encryption technique which is replacement to DES algorithm and that is  very powerful ammunition against hackers and cyber-criminals. It is utilized in a wide array of products like in performance-constrained environments such as embedded systems, secure E-mail encryption tools, backup software, password management tools.

Ø  It is a symmetric key encryption algorithm in which the same secret key is used for both encryption and decryption i.e. same secret key is used by sender and receiver and it is kept secret.

Ø  It is 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 448 bits(variable length key is used)

Ø  It is compact i.e. executes in less memory and simple (XOR, Addition etc operations are performed here) algorithm.

Ø  It is a 16-round Feistel cipher and uses large key-dependent Substitution-boxes(S-Box)

SOURCE CODE:


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();
    }
}

OUTPUT:


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



Comments

  1. unable to copy your code.
    Please check it.
    If its image please replace it with text as it would be very much helpful for your viewers.

    ReplyDelete

Post a Comment

Search related post on google