Decrypting in Java with Blowfish

后端 未结 6 1932
独厮守ぢ
独厮守ぢ 2021-02-06 18:41

Hullo,

I am encrypting and decrypting in Java with Blowfish.

The encryption works fine, but the decryption fails.

Here is my Java code for decrypting :

6条回答
  •  误落风尘
    2021-02-06 19:18

    String encryptedString = … ;  
    String decryptedString = null;
    SecretKeySpec key = new SecretKeySpec(myKey.getBytes(), "Blowfish");
    private static byte[] linebreak = {}; // Remove Base64 encoder default linebreak
    private static Base64 coder;
    Cipher cipher;
    try {
        coder = new Base64(32, linebreak, true);
        cipher = Cipher.getInstance("Blowfish");
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] decrypted = cipher.doFinal(encryptedString.getBytes());
        decryptedString = new String(coder.encode(decrypted));
    } [ catch Exceptions … ]
    

    You can use Base64 class to solve this problem.

提交回复
热议问题