added check to see if browser is gcm compliant

This commit is contained in:
Abhinav Adduri 2017-07-10 13:27:01 -07:00
parent 2031158336
commit 64998de423
3 changed files with 55 additions and 2 deletions

View file

@ -32,8 +32,42 @@ function notify(str) {
}
}
function gcmCompliant() {
try {
return window.crypto.subtle.generateKey(
{
name: 'AES-GCM',
length: 128
},
true,
['encrypt', 'decrypt']
).then(key => {
return window.crypto.subtle.encrypt(
{
name: 'AES-GCM',
iv: window.crypto.getRandomValues(new Uint8Array(12)),
additionalData: window.crypto.getRandomValues(new Uint8Array(6))
},
key,
new ArrayBuffer(8)
)
.then(() => {
return Promise.resolve()
})
.catch(err => {
return Promise.reject()
})
}).catch(err => {
return Promise.reject();
})
} catch(err) {
return Promise.reject();
}
}
module.exports = {
arrayToHex,
hexToArray,
notify
notify,
gcmCompliant
};