Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch from keypairs to single encryption keys

Since we have removed the HMACing, there is no need to have two
keys anymore.
  • Loading branch information...
commit ebc42e6afd551e5b488e0f447bedc3ba8210b2c9 1 parent eb24e4a
@fmarier authored
Showing with 10 additions and 12 deletions.
  1. +10 −12 static/crypto.js
View
22 static/crypto.js
@@ -15,9 +15,9 @@ function encrypt() {
$('#encrypt-button').hide();
$('#encryption-message').text('Encrypting message...');
- var keypair = loadLocalKey();
+ var encryptionKey = loadLocalKey();
var plaintext = $('#note-content').val();
- var encryption = jwcrypto.encrypt(plaintext, keypair);
+ var encryption = jwcrypto.encrypt(plaintext, encryptionKey);
setTimeout(
function () {
@@ -31,8 +31,8 @@ function decrypt() {
$('#decrypt-button').hide();
$('#decryption-message').text('Decrypting message...');
- var keypair = loadLocalKey();
- var plaintext = jwcrypto.decrypt($('#note-content').text(), keypair);
+ var encryptionKey = loadLocalKey();
+ var plaintext = jwcrypto.decrypt($('#note-content').text(), encryptionKey);
setTimeout(
function () {
@@ -44,9 +44,7 @@ function decrypt() {
function generateUserKey(assertion, cb) {
setTimeout(function () {
// TODO: generate a random key
- var key = jwcryptoutils.base64urlencode(JSON.stringify(
- {encryptionKey: jwcryptolibs.sjcl.hash.sha256.hash('secret encryption key'),
- macKey: jwcryptolibs.sjcl.hash.sha256.hash('secret mac key')}));
+ var key = jwcryptoutils.base64urlencode(jwcryptolibs.sjcl.hash.sha256.hash('secret encryption key'));
var wrappedKey = key.split('').reverse().join(''); // TODO: actually wrap the key!
cb(key, wrappedKey);
@@ -54,12 +52,12 @@ function generateUserKey(assertion, cb) {
}
function loadLocalKey() {
- var keypair = localStorage.getItem('keypair');
+ var encryptionKey = localStorage.getItem('encryptionkey');
// TODO: if it's not available, should we redirect to /loggedin?
- return JSON.parse(keypair);
+ return encryptionKey;
}
-function storeLocalKey(realKey) {
- var decodedKey = jwcryptoutils.base64urldecode(realKey);
- localStorage.setItem('keypair', decodedKey);
+function storeLocalKey(plainKey) {
+ var decodedKey = jwcryptoutils.base64urldecode(plainKey);
+ localStorage.setItem('encryptionkey', decodedKey);
}
Please sign in to comment.
Something went wrong with that request. Please try again.