crypto-js aes can't decrypt what it encrypted

前端 未结 1 956
你的背包
你的背包 2020-12-07 03:44

Hello I\'m trying to decrypt a encrypted aes string with crypto-js but it seems like it doesn\'t work right.

I\'m using:



        
相关标签:
1条回答
  • 2020-12-07 04:41

    The return type of all CryptoJS.<blockcipher>.decrypt() functions is a WordArray which is the native representation of binary data in CryptoJS. When you force it to be printed (automatically calling toString()), the binary data that it contains will be Hex encoded.

    If you want to have a different encoding, then you need to specify it. Here are some examples:

    console.log(decrypted.toString()); // Hex encoded
    console.log(decrypted.toString(CryptoJS.enc.Hex)); // Hex encoded
    console.log(CryptoJS.enc.Hex.stringify(decrypted)); // Hex encoded
    
    console.log(decrypted.toString(CryptoJS.enc.Utf8)); // UTF-8 encoded
    console.log(CryptoJS.enc.Utf8.stringify(decrypted)); // UTF-8 encoded
    
    console.log(decrypted.toString(CryptoJS.enc.Base64)); // Base64 encoded
    console.log(CryptoJS.enc.Base64.stringify(decrypted)); // Base64 encoded
    
    0 讨论(0)
提交回复
热议问题