Untitled
unknown
plain_text
a year ago
1.3 kB
14
Indexable
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.util.Base64;
public class BlowFishCipher {
public static void main(String[] args) throws Exception {
// Generate Blowfish key
KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish");
SecretKey secretKey = keyGenerator.generateKey();
// Initialize cipher for encryption
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
// Input text to encrypt
String inputText = "Hello World";
byte[] encrypted = cipher.doFinal(inputText.getBytes());
// Convert encrypted bytes to Base64 for readable output
String encryptedText = Base64.getEncoder().encodeToString(encrypted);
// Initialize cipher for decryption
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decrypted = cipher.doFinal(encrypted);
// Convert decrypted bytes back to string
String decryptedText = new String(decrypted);
// Print results
System.out.println("Original String: " + inputText);
System.out.println("Encrypted (Base64): " + encryptedText);
System.out.println("Decrypted: " + decryptedText);
}
}Editor is loading...
Leave a Comment