only access window.crypto.webkitSubtle in fallback
This commit is contained in:
parent
79d2e9d6bf
commit
3c2871a0e4
|
@ -146,18 +146,7 @@ export default function RSA() {
|
||||||
let keyGenOpt;
|
let keyGenOpt;
|
||||||
|
|
||||||
let keys;
|
let keys;
|
||||||
if (window.crypto && window.crypto.webkitSubtle) {
|
if ((window.crypto && window.crypto.subtle) || window.msCrypto) {
|
||||||
// outdated spec implemented by Webkit
|
|
||||||
keyGenOpt = {
|
|
||||||
name: 'RSA-OAEP',
|
|
||||||
modulusLength: B, // the specified keysize in bits
|
|
||||||
publicExponent: Euint8.subarray(0, 3), // take three bytes (max 65537)
|
|
||||||
hash: {
|
|
||||||
name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
keys = webCrypto.generateKey(keyGenOpt, true, ['encrypt', 'decrypt']);
|
|
||||||
} else {
|
|
||||||
// current standard spec
|
// current standard spec
|
||||||
keyGenOpt = {
|
keyGenOpt = {
|
||||||
name: 'RSASSA-PKCS1-v1_5',
|
name: 'RSASSA-PKCS1-v1_5',
|
||||||
|
@ -173,6 +162,21 @@ export default function RSA() {
|
||||||
keys = util.promisifyIE11Op(keys, 'Error generating RSA key pair.');
|
keys = util.promisifyIE11Op(keys, 'Error generating RSA key pair.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (window.crypto && window.crypto.webkitSubtle) {
|
||||||
|
// outdated spec implemented by old Webkit
|
||||||
|
keyGenOpt = {
|
||||||
|
name: 'RSA-OAEP',
|
||||||
|
modulusLength: B, // the specified keysize in bits
|
||||||
|
publicExponent: Euint8.subarray(0, 3), // take three bytes (max 65537)
|
||||||
|
hash: {
|
||||||
|
name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
keys = webCrypto.generateKey(keyGenOpt, true, ['encrypt', 'decrypt']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error('Unknown WebCrypto implementation');
|
||||||
|
}
|
||||||
|
|
||||||
return keys.then(exportKey).then(function(key) {
|
return keys.then(exportKey).then(function(key) {
|
||||||
if (key instanceof ArrayBuffer) {
|
if (key instanceof ArrayBuffer) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user