Privacy/Features/DOMCryptAPI/UseCases: Difference between revisions

Line 28: Line 28:
</pre>
</pre>


=== General Purpose Symmetric Crypto ===
=== Symmetric Crypto via Diffie-Hellman Key Exchange ===


* 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.
* TBD
 
Example Code uses the symmetric encryption API: '''window.cipher.sym.*'''


<pre class="brush:js;toolbar:false;">
<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...
  // This API is under development
 
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>


564

edits