栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Java的AES加密和使用Java的解密

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Java的AES加密和使用Java的解密

  1. 您的Java代码使用128位AES密钥,而Javascript代码使用256位AES密钥。

  2. 您的Java代码使用“ Abcdefghijklmnop” .getBytes()作为实际键值,而您的Javascript代码使用“ Abcdefghijklmnop”作为导出实际密钥的密码。

  3. Java AES的默认转换是AES / ECB / PKCS5Padding,而CryptoJS的默认转换是AES / CBC / PKCS7Padding。

解决示例的一种方法是修复Javascript方面:

// this is base64 representation of the Java counterpart// byte[] keyValue = new byte[] { 'A', 'b', 'c', 'd', 'e', 'f', 'g',//     'h', 'i', 'j', 'k','l', 'm', 'n', 'o', 'p'};// String keyForJS = new base64Enprer().enpre(keyValue);var base64Key = "QWJjZGVmZ2hpamtsbW5vcA==";console.log( "base64Key = " + base64Key );// this is the actual key as a sequence of bytesvar key = CryptoJS.enc.base64.parse(base64Key);console.log( "key = " + key );// this is the plain textvar plaintText = "Hello, World!";console.log( "plaintText = " + plaintText );// this is base64-enpred encrypted datavar encryptedData = CryptoJS.AES.encrypt(plaintText, key, {    mode: CryptoJS.mode.ECB,    padding: CryptoJS.pad.Pkcs7});console.log( "encryptedData = " + encryptedData );// this is the decrypted data as a sequence of bytesvar decryptedData = CryptoJS.AES.decrypt( encryptedData, key, {    mode: CryptoJS.mode.ECB,    padding: CryptoJS.pad.Pkcs7} );console.log( "decryptedData = " + decryptedData );// this is the decrypted data as a stringvar decryptedText = decryptedData.toString( CryptoJS.enc.Utf8 );console.log( "decryptedText = " + decryptedText );


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/516509.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号