const { enc, AES } = require("crypto-js");
const KEY = enc.Utf8.parse("this is a key");
const IV = enc.Utf8.parse("this is initial vector");
const originalText = "someone@example.com";
const hash = AES.encrypt(originalText, KEY, { iv: IV });
const hashText = hash.toString();
console.log(`"${originalText}" was encrypted to "${hashText}"`);
const hashTextCopy = `${hashText}`;
const decrypt = AES.decrypt(hashTextCopy, KEY, { iv: IV });
const decryptText = decrypt.toString(enc.Utf8);
console.log(`"${hashTextCopy}" was decrypted to "${decryptText}"`);
我得到的输出是:
"someone@example.com" was encrypted to "IgyDXGNVD8IokknoZqjamG0QecGvBM/dyxx4il8gCHA="
"IgyDXGNVD8IokknoZqjamG0QecGvBM/dyxx4il8gCHA=" was decrypted to ""
有人能解释一下是怎么回事吗?我在互联网上看到了很多这样的例子,它们看起来都很好。但在这里,文本没有被解密。
ps:我使用的版本是“crypto-js”:“^3.1.9-1”,
也许试着稍微改变一下你的代码,这对我来说是可行的。
正如评论中所述,我相信您最初示例的问题是密钥长度。
const { enc, AES } = require("crypto-js");
// Keep as a string..
const KEY = "this is a key";
const IV = enc.Utf8.parse("this is initial vector");
const originalText = "someone@example.com";
const hash = AES.encrypt(originalText, KEY, { iv: IV });
const hashText = hash.toString();
console.log(`"${originalText}" was encrypted to "${hashText}"`);
const hashTextCopy = `${hashText}`;
const decrypt = AES.decrypt(hashTextCopy, KEY, { iv: IV });
const decryptText = decrypt.toString(enc.Utf8);
console.log(`"${hashTextCopy}" was decrypted to "${decryptText}"`);
这也起作用:
const { enc, AES } = require("crypto-js");
// 128-bit key works nicely
const KEY = enc.Hex.parse("000102030405060708090a0b0c0d0e0f");
const IV = enc.Utf8.parse("this is initial vector");
const originalText = "someone@example.com";
const hash = AES.encrypt(originalText, KEY, { iv: IV });
const hashText = hash.toString();
console.log(`"${originalText}" was encrypted to "${hashText}"`);
const hashTextCopy = `${hashText}`;
const decrypt = AES.decrypt(hashTextCopy, KEY, { iv: IV });
const decryptText = decrypt.toString(enc.Utf8);
console.log(`"${hashTextCopy}" was decrypted to "${decryptText}"`);
const KEY = enc.Utf8.parse("abcdfghi");
const KEY = enc.Utf8.parse("abcdfghijklmnopq");
所以我使用下面的代码来加密/解密可以存储在设备首选项中的字符串值,但我知道需要添加一个加密/解密ArrayList的方法,该方法也可以存储在首选项中(所以我猜加密需要将arraylist转换为字符串,然后解密需要将该字符串转换回arraylist)。由于我对Android/Java非常陌生,因此我很难弄清楚如何做到这一点,因此任何帮助都将不胜感激。
我感兴趣的是构建一个个人使用的小应用程序,它将使用JavaScript在客户端加密和解密信息。加密的信息将存储在服务器上的数据库中,但不会存储解密的版本。 它不一定要是超级duper安全的,但我想使用一个当前未中断的算法。 理想情况下我可以做一些 生成编码字符串,以及类似于 以后再解码。 到目前为止,我已经看到了以下内容:http://bitwiseshiftleft.github.io/sjcl
我正在编写一个程序,以这种方式加密一个给定的字符串: 如果我们有一个整数V和一个只有元音的数组v={a,e,I,o,u}如果字符串的字母是一个元音,那么用它前面V个位置的元音替换它,只考虑元音的数组(不是整个字母表!). 要明确: 所以为了解决我的问题,我写了: 代码采用字符串的每个元素来验证它是否是元音,然后如果它是元音,则将字符串的考虑元素替换为 V 位置之前的元音。 如果字符串只有元音 i,
V1.1.1新增 <?php $string='666666'; $string=sp_authencode($string);//加密字符串 echo $string;//输出加密后的字符串 ?>
V1.1.1新增 <?php $string='1324123i412qewrwerqwe'; $string=sp_authcode($string);//解密字符串 echo $string;//输出解密后的字符串 ?>
问题内容: 我是密码学的新手。我希望学习如何在文件中加密和解密文本……当我在net中引用相关文章时。我怀疑对同一文本进行多次加密后,单个文本的加密文本是否会相同?谁能解决我的疑问? 问题答案: 这是使用该类的示例: