如何使用iv param和SecretKeySpec从java代码解密cryptojs aes

时间:2018-01-23 12:24:36

标签: javascript java encryption aes cryptojs

从java代码我有一个代码:

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", new BouncyCastleProvider());
byte[] keys = Base64.decodeBase64(encryptionKey);
SecretKey speckey = new SecretKeySpec(keys, "AES");
byte[] ivParam = new byte[cipher.getBlockSize()];
System.arraycopy(speckey.getEncoded(), 0, ivParam, 0, ivParam.length);
cipher.init(cipherMode, speckey, new IvParameterSpec(ivParam));
return cipher;

在javascript中我有一个要解密的脚本,但它不起作用:

var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
    iv: iv,
    padding: CryptoJS.pad.Pkcs7,
    mode: CryptoJS.mode.CBC
  })
  console.log("Decrypted: ", decrypted.toString(CryptoJS.enc.Utf8));

我知道我们需要解析iv(像这个var iv = CryptoJS.enc.Hex.parse(pass);但它不起作用),密钥并且可能首先加密以解密但我不知道上面的Java代码我们如何解析iv和密钥解密。谁曾在此工作过请帮助我。非常感谢< 3

0 个答案:

没有答案