Decrypt AES/CBC/PKCS5Padding with CryptoJS

前端 未结 2 1544
Happy的楠姐
Happy的楠姐 2021-02-11 09:46

I generate 128bit AES/CBC/PKCS5Padding key using Java javax.crypto API. Here is the algorithm that I use:

public static String encryptA         


        
2条回答
  •  感动是毒
    2021-02-11 10:26

    This one perfectly worked for me

    import * as CryptoJS from 'crypto-js';    
    const SECRET_CREDIT_CARD_KEY = '1231231231231231' // 16 digits key
        
        decrypt(cipherText) {
            const iv = CryptoJS.enc.Hex.parse(this.SECRET_CREDIT_CARD_KEY);
            const key = CryptoJS.enc.Utf8.parse(this.SECRET_CREDIT_CARD_KEY);
            const result = CryptoJS.AES.decrypt(cipherText, key,
              {
                iv,
                mode: CryptoJS.mode.ECB,
              }
              )
              const final  = result.toString(CryptoJS.enc.Utf8)
              return final
          }
        
        console.log(decrypt('your encrypted text'))
    

    using this library in Angular 8 https://www.npmjs.com/package/crypto-js

提交回复
热议问题