Different output encryption both CryptoJS and Java Code

后端 未结 3 1508
攒了一身酷
攒了一身酷 2021-01-31 12:10

I need to encrypt certainly string from client-side (JavaScript) and decrypt from server-side (Java), so I found CryptoJS and I write the code with the same params/configuration

3条回答
  •  隐瞒了意图╮
    2021-01-31 12:45

    Very usefull example SoldierCorp, thank you!

    Few things to improve your example:

    • Method padString does not support UTF8 and instead of fixing this method lets delete it and use a standard padding

    in javascript replace on

    padding: CryptoJS.pad.Pkcs7
    

    in java replace on

    algorithm = "AES/CBC/PKCS5Padding"
    
    • Generate key from any string phrase (for IV can be the same)

    in javascript replace on

    var key = CryptoJS.MD5("Secret Passphrase");
    

    in java replace on

    byte[] keyValue = org.apache.commons.codec.digest.DigestUtils.md5("Secret Passphrase");
    

提交回复
热议问题