gcm encryption
This commit is contained in:
parent
a7fcb1a44f
commit
50995238bd
|
@ -54,36 +54,32 @@ class FileReceiver extends EventEmitter {
|
||||||
{
|
{
|
||||||
kty: 'oct',
|
kty: 'oct',
|
||||||
k: location.hash.slice(1),
|
k: location.hash.slice(1),
|
||||||
alg: 'A128CBC',
|
alg: 'A256GCM',
|
||||||
ext: true
|
ext: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'AES-CBC'
|
name: 'AES-GCM'
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
['encrypt', 'decrypt']
|
['encrypt', 'decrypt']
|
||||||
)
|
)
|
||||||
])
|
]).then(([fdata, key]) => {
|
||||||
.then(([fdata, key]) => {
|
const salt = this.salt;
|
||||||
const salt = this.salt;
|
return Promise.all([
|
||||||
return Promise.all([
|
window.crypto.subtle.decrypt(
|
||||||
window.crypto.subtle.decrypt(
|
{
|
||||||
{
|
name: 'AES-GCM',
|
||||||
name: 'AES-CBC',
|
iv: salt,
|
||||||
iv: salt
|
tagLength: 128
|
||||||
},
|
},
|
||||||
key,
|
key,
|
||||||
fdata.data
|
fdata.data
|
||||||
),
|
),
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
resolve(fdata.fname);
|
resolve(fdata.fname);
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
})
|
});
|
||||||
.catch(err => {
|
|
||||||
Raven.captureException(err);
|
|
||||||
return Promise.reject(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ class FileSender extends EventEmitter {
|
||||||
constructor(file) {
|
constructor(file) {
|
||||||
super();
|
super();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.iv = window.crypto.getRandomValues(new Uint8Array(16));
|
this.iv = window.crypto.getRandomValues(new Uint8Array(12));
|
||||||
}
|
}
|
||||||
|
|
||||||
static delete(fileId, token) {
|
static delete(fileId, token) {
|
||||||
|
@ -39,12 +39,13 @@ class FileSender extends EventEmitter {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
window.crypto.subtle.generateKey(
|
window.crypto.subtle.generateKey(
|
||||||
{
|
{
|
||||||
name: 'AES-CBC',
|
name: 'AES-GCM',
|
||||||
length: 128
|
length: 256,
|
||||||
|
tagLength: 128
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
['encrypt', 'decrypt']
|
['encrypt', 'decrypt']
|
||||||
),
|
).catch(err => console.log('There was an error generating a crypto key')),
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsArrayBuffer(this.file);
|
reader.readAsArrayBuffer(this.file);
|
||||||
|
@ -57,12 +58,13 @@ class FileSender extends EventEmitter {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
window.crypto.subtle.encrypt(
|
window.crypto.subtle.encrypt(
|
||||||
{
|
{
|
||||||
name: 'AES-CBC',
|
name: 'AES-GCM',
|
||||||
iv: this.iv
|
iv: this.iv,
|
||||||
|
tagLength: 128
|
||||||
},
|
},
|
||||||
secretKey,
|
secretKey,
|
||||||
plaintext
|
plaintext
|
||||||
),
|
).catch(err => console.log('Error with encrypting.')),
|
||||||
window.crypto.subtle.exportKey('jwk', secretKey)
|
window.crypto.subtle.exportKey('jwk', secretKey)
|
||||||
]);
|
]);
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,7 +12,7 @@ function ivToStr(iv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function strToIv(str) {
|
function strToIv(str) {
|
||||||
const iv = new Uint8Array(16);
|
const iv = new Uint8Array(12);
|
||||||
for (let i = 0; i < str.length; i += 2) {
|
for (let i = 0; i < str.length; i += 2) {
|
||||||
iv[i / 2] = parseInt(str.charAt(i) + str.charAt(i + 1), 16);
|
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 => {
|
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