diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-10-15 07:26:44 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-10-15 07:26:44 +0800 |
commit | 69aed23e9b8af5b620576ad5586d37eea99793ef (patch) | |
tree | 3738cacbe94f5fb7ad2ded77919ef5aff8547e39 | |
parent | 1c791c4d2e7f280b634a5fe1bb449d5d05c9db7c (diff) | |
download | tangerine-wallet-browser-69aed23e9b8af5b620576ad5586d37eea99793ef.tar tangerine-wallet-browser-69aed23e9b8af5b620576ad5586d37eea99793ef.tar.gz tangerine-wallet-browser-69aed23e9b8af5b620576ad5586d37eea99793ef.tar.bz2 tangerine-wallet-browser-69aed23e9b8af5b620576ad5586d37eea99793ef.tar.lz tangerine-wallet-browser-69aed23e9b8af5b620576ad5586d37eea99793ef.tar.xz tangerine-wallet-browser-69aed23e9b8af5b620576ad5586d37eea99793ef.tar.zst tangerine-wallet-browser-69aed23e9b8af5b620576ad5586d37eea99793ef.zip |
Fixed vector usage in encryptor
-rw-r--r-- | app/scripts/lib/encryptor.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/app/scripts/lib/encryptor.js b/app/scripts/lib/encryptor.js index 207a9fc3c..4b3c7eb8e 100644 --- a/app/scripts/lib/encryptor.js +++ b/app/scripts/lib/encryptor.js @@ -2,12 +2,21 @@ var ethUtil = require('ethereumjs-util') var vector = global.crypto.getRandomValues(new Uint8Array(16)) module.exports = { + + // Simple encryption methods: encrypt, decrypt, - convertArrayBufferViewtoString, + + // More advanced encryption methods: keyFromPassword, encryptWithKey, decryptWithKey, + + // Buffer <-> String methods + convertArrayBufferViewtoString, + convertStringToArrayBufferView, + + // Buffer <-> Hex string methods serializeBufferForStorage, serializeBufferFromStorage, } @@ -23,13 +32,15 @@ function encrypt (password, dataObj) { function encryptWithKey (key, dataObj) { var data = JSON.stringify(dataObj) var dataBuffer = convertStringToArrayBufferView(data) + var vector = global.crypto.getRandomValues(new Uint8Array(16)) return global.crypto.subtle.encrypt({ name: 'AES-GCM', iv: vector }, key, dataBuffer).then(function(buf){ var buffer = new Uint8Array(buf) - return serializeBufferForStorage(buffer) + var vectorStr = serializeBufferForStorage(vector) + return serializeBufferForStorage(buffer) + vectorStr }) } @@ -43,7 +54,10 @@ function decrypt (password, text) { // AUDIT: See if this still works when generating a fresh vector function decryptWithKey (key, text) { - const encryptedData = serializeBufferFromStorage(text) + const parts = text.split('0x') + const encryptedData = serializeBufferFromStorage(parts[1]) + const vector = serializeBufferFromStorage(parts[2]) + debugger return crypto.subtle.decrypt({name: "AES-GCM", iv: vector}, key, encryptedData) .then(function(result){ const decryptedData = new Uint8Array(result) |