Encryption and Decryption using Blowfish Error - Input length must be multiple of 8 when decrypting with padded cipher

后端 未结 3 1066
囚心锁ツ
囚心锁ツ 2021-02-06 19:59

I am able to encrypt data however when decrypting it i am getting the following error:

Error

HTTP Status 500 - Request processing failed         


        
3条回答
  •  独厮守ぢ
    2021-02-06 20:11

    The problem is with the way you are creating String instances out of the raw encrypted byte[] data. You need to either use binhex encoding like that provided by javax.xml.bind.DatatypeConverter via the parseHexBinary and printHexBinary methods or base 64 using the parseBase64Binary and printBase64Binary methods of the same object.

    One other word of advice, never rely on the default mode and padding, always be explicit. Use something like Cipher.getInstance("Blowfish/CBC/PKCS5Padding") depending on what your needs are.

提交回复
热议问题