简体   繁体   English

如何加密HTML5网络存储?

[英]How can I encrypt HTML5 web storage?

Is mcrypt or cryptojs better? mcrypt还是cryptoj更好?

Can anyone give me an example how I can encrypt web storage with HML5? 任何人都可以给我一个例子,说明如何使用HML5加密网络存储?

HTML: 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: 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);
}

In addition to my comment up there.. it wouldn't have any difference storing regular or encrypted data.. since local storage only accepts text then if you're storing JSON for example it needs to be stringified first.. so before storing you stringify -> then encrypt -> then store.. and on retrieve you retrieve -> then decrypt -> then parse. 除了我在那里的评论..存储常规或加密数据没有任何区别..因为本地存储只接受文本然后如果你存储JSON例如它需要首先进行字符串化..所以在存储之前stringify - >然后加密 - >然后存储..然后检索你检索 - >然后解密 - >然后解析。

I've used CryptoJS once and that was for Hash calculation where I used to send the hashing salt via SMS.. and it was really working good. 我曾经使用过一次CryptoJS,这是用于哈希计算的地方,我曾经通过短信发送哈希盐...它确实很好用。

An example for encryption/decryption using for example AES is: 使用例如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 演示链接:寻找控制台

You must use server side encryption like Mcrypt if using PHP and then encode it with Base64. 如果使用PHP,则必须使用像Mcrypt这样的服务器端加密,然后使用Base64对其进行编码。

var nama = '<?php echo $base64EncryptedValue; ?>';
localStorage.setItem('datnama', nama);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM