Privacy/Features/DOMCryptAPI/UseCases: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 41: Line 41:
var diaryEntry = document.getElementById("diary-entry").textContent;
var diaryEntry = document.getElementById("diary-entry").textContent;


window.cipher.sym.encrypt(diaryEntry, document.currentKey, function callback(cipherText){
window.cipher.sym.encrypt(diaryEntry, document.currentKey, function callback(cipherText) {
   var entryID = diaryApp.getSequence();
   var entryID = diaryApp.getSequence();
   localStorage.setItem(entryID, cipherText);
   localStorage.setItem(entryID, cipherText);
Line 49: Line 49:
// decryption
// decryption


window.cipher.sym.decrypt(localStorage.getItem(entryID), document.currentKey, function callback(plainText){
window.cipher.sym.decrypt(localStorage.getItem(entryID), document.currentKey, function callback(plainText) {
   document.getElementById("diary-entry").textContent = plainText;
   document.getElementById("diary-entry").textContent = plainText;
});
});
</pre>


=== Hashing ===


SHA 256 hashes are handy for storing passwords and generating checksums (among other uses)


Example code:
<pre class="brush:js;toolbar:false;">
var myPassword = "5ekr3tPa55w0rd";
window.cipher.hash.SHA256(myPassword, function callback(aHash) {
  myApp.doSomethingWithAHash(aHash); 
});
</pre>
</pre>
// Another idea: generating a file checksum in conjunction with the FileAPI
564

edits

Navigation menu