Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

encryption - JavaScript字符串加密和解密?(JavaScript string encryption and decryption?)

I'm interested in building a small app for personal use that will encrypt and decrypt information on the client side using JavaScript.

(我对构建一个供个人使用的小型应用程序感兴趣,该应用程序将使用JavaScript在客户端加密和解密信息。)

The encrypted information will be stored in a database on a server, but never the decrypted version.

(加密的信息将存储在服务器上的数据库中,但不会存储在解密版本中。)

It doesn't have to be super duper secure, but I would like to use a currently unbroken algorithm.

(它不必是超级duper安全的,但是我想使用当前不间断的算法。)

Ideally I'd be able to do something like

(理想情况下,我可以做类似的事情)

var gibberish = encrypt(string, salt, key);

to generate the encoded string, and something like

(生成编码的字符串,诸如此类)

var sensical = decrypt(gibberish, key);

to decode it later.

(稍后再解码。)

So far I've seen this: http://bitwiseshiftleft.github.io/sjcl/

(到目前为止,我已经看到了: http : //bitwiseshiftleft.github.io/sjcl/)

Any other libraries I should look at?

(我应该看看其他图书馆吗?)

  ask by jeremiahs translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

  var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase"); //U2FsdGVkX18ZUVvShFSES21qHsQEqZXMxQ9zgHy+bu0= var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase"); //4d657373616765 document.getElementById("demo1").innerHTML = encrypted; document.getElementById("demo2").innerHTML = decrypted; document.getElementById("demo3").innerHTML = decrypted.toString(CryptoJS.enc.Utf8); 
 Full working sample actually is: <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script> <br><br> <label>encrypted</label> <div id="demo1"></div> <br> <label>decrypted</label> <div id="demo2"></div> <br> <label>Actual Message</label> <div id="demo3"></div> 


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...