mcrypt还是cryptoj更好?
任何人都可以给我一个例子,说明如何使用HML5加密网络存储?
HTML:
<div id="Data Personal">
<h1>Silakan Masukkan Data</h1>
<div>Nama = <span id="nama" contenteditable="true" onkeyup="storeMyContact(this.id)"></span></div>
<div>telepon = <span id="Telepon" contenteditable="true" onkeyup="storeMyContact(this.id)"></span></div>
<div>Email = <span id="email" contenteditable="true" onkeyup="storeMyContact(this.id)"></span></div>
<div>Kartu kredit = <span id="cc" contenteditable="true"onkeyup="storeMyContact(this.id)"></span></div>
</div>
JavaScript的:
function storeMyContact(id) {
var nama = document.getElementById('nama').innerHTML;
var Telepon = document.getElementById('Telepon').innerHTML;
var email = document.getElementById('email').innerHTML;
var cc = document.getElementById('cc').innerHTML;
localStorage.setItem('datnama', nama);
localStorage.setItem('dattlp', Telepon);
localStorage.setItem('datemail', email);
localStorage.setItem('datcc', cc);
}
解决方法:
除了我在那里的评论..存储常规或加密数据没有任何区别..因为本地存储只接受文本然后如果你存储JSON例如它需要首先进行字符串化..所以在存储之前stringify – >然后加密 – >然后存储..并检索您检索 – >然后解密 – >然后解析.
我曾经使用过一次CryptoJS,这是用于哈希计算的地方,我曾经通过短信发送哈希盐…它确实很好用.
使用例如AES的加密/解密的示例是:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js">
</script>
<script>
var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
</script>
The howto here is straightforward and easy to follow
Demo Link : Look for the Console