gcm encryption
This commit is contained in:
parent
a7fcb1a44f
commit
50995238bd
@ -54,23 +54,23 @@ class FileReceiver extends EventEmitter {
|
||||
{
|
||||
kty: 'oct',
|
||||
k: location.hash.slice(1),
|
||||
alg: 'A128CBC',
|
||||
alg: 'A256GCM',
|
||||
ext: true
|
||||
},
|
||||
{
|
||||
name: 'AES-CBC'
|
||||
name: 'AES-GCM'
|
||||
},
|
||||
true,
|
||||
['encrypt', 'decrypt']
|
||||
)
|
||||
])
|
||||
.then(([fdata, key]) => {
|
||||
]).then(([fdata, key]) => {
|
||||
const salt = this.salt;
|
||||
return Promise.all([
|
||||
window.crypto.subtle.decrypt(
|
||||
{
|
||||
name: 'AES-CBC',
|
||||
iv: salt
|
||||
name: 'AES-GCM',
|
||||
iv: salt,
|
||||
tagLength: 128
|
||||
},
|
||||
key,
|
||||
fdata.data
|
||||
@ -79,10 +79,6 @@ class FileReceiver extends EventEmitter {
|
||||
resolve(fdata.fname);
|
||||
})
|
||||
]);
|
||||
})
|
||||
.catch(err => {
|
||||
Raven.captureException(err);
|
||||
return Promise.reject(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ class FileSender extends EventEmitter {
|
||||
constructor(file) {
|
||||
super();
|
||||
this.file = file;
|
||||
this.iv = window.crypto.getRandomValues(new Uint8Array(16));
|
||||
this.iv = window.crypto.getRandomValues(new Uint8Array(12));
|
||||
}
|
||||
|
||||
static delete(fileId, token) {
|
||||
@ -39,12 +39,13 @@ class FileSender extends EventEmitter {
|
||||
return Promise.all([
|
||||
window.crypto.subtle.generateKey(
|
||||
{
|
||||
name: 'AES-CBC',
|
||||
length: 128
|
||||
name: 'AES-GCM',
|
||||
length: 256,
|
||||
tagLength: 128
|
||||
},
|
||||
true,
|
||||
['encrypt', 'decrypt']
|
||||
),
|
||||
).catch(err => console.log('There was an error generating a crypto key')),
|
||||
new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsArrayBuffer(this.file);
|
||||
@ -57,12 +58,13 @@ class FileSender extends EventEmitter {
|
||||
return Promise.all([
|
||||
window.crypto.subtle.encrypt(
|
||||
{
|
||||
name: 'AES-CBC',
|
||||
iv: this.iv
|
||||
name: 'AES-GCM',
|
||||
iv: this.iv,
|
||||
tagLength: 128
|
||||
},
|
||||
secretKey,
|
||||
plaintext
|
||||
),
|
||||
).catch(err => console.log('Error with encrypting.')),
|
||||
window.crypto.subtle.exportKey('jwk', secretKey)
|
||||
]);
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ function ivToStr(iv) {
|
||||
}
|
||||
|
||||
function strToIv(str) {
|
||||
const iv = new Uint8Array(16);
|
||||
const iv = new Uint8Array(12);
|
||||
for (let i = 0; i < str.length; i += 2) {
|
||||
iv[i / 2] = parseInt(str.charAt(i) + str.charAt(i + 1), 16);
|
||||
}
|
||||
|
@ -171,5 +171,5 @@ app.listen(conf.listen_port, () => {
|
||||
});
|
||||
|
||||
const validateID = route_id => {
|
||||
return route_id.match(/^[0-9a-fA-F]{32}$/) !== null;
|
||||
return route_id.match(/^[0-9a-fA-F]{24}$/) !== null;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user