564
edits
(Created page with "== DOMCrypt API Use Cases == === Messaging === * Natasha and Boris would like to message one another privately via a web application. The server is untrusted and all message da...") |
No edit summary |
||
Line 22: | Line 22: | ||
messagingApp.sendMessage(aCipherMessage, {from: 'natasha', to: 'boris'}); | messagingApp.sendMessage(aCipherMessage, {from: 'natasha', to: 'boris'}); | ||
}); | }); | ||
</pre> | |||
=== General Purpose Symmetric Crypto === | |||
* A web developer would like to use localStorage or IndexedDB in her diary web application, but would really like all data stored locally to be encrypted should the machine get stolen or 'borrowed' by an unauthorized user. | |||
Example Code: | |||
<pre class="brush:js;toolbar:false;"> | |||
// create an encryption key and keep it around for later use - perhaps it is also saved to the server... | |||
window.cipher.sym.generateKey(function callback(key){ | |||
document.currentKey = key; | |||
diaryApp.saveKeyToServer(key); | |||
}); | |||
// save the current diary entry: | |||
var diaryEntry = document.getElementById("diary-entry").textContent; | |||
window.cipher.sym.encrypt(diaryEntry, document.currentKey, function callback(cipherText){ | |||
var entryID = diaryApp.getSequence(); | |||
localStorage.setItem(entryID, cipherText); | |||
alert("Diary entry saved successfully"); | |||
}); | |||
// decryption | |||
window.cipher.sym.decrypt(localStorage.getItem(entryID), document.currentKey, function callback(plainText){ | |||
document.getElementById("diary-entry").textContent = plainText; | |||
}); | |||
</pre> | </pre> |
edits