I am creating a keyPair, then exporting a key from the keyPair, using the Web Crypto API:
var log = console.log.bind(console);
var subtleCrypto = null;
if ( window.crypto ) {
subtleCrypto = window.crypto.subtle || window.crypto.webkitSubtle;
}
if ( window.msCrypto ) {
subtleCrypto = window.msCrypto.subtle
}
subtleCrypto.generateKey(
{
name: "RSASSA-PKCS1-v1_5",
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]), // 24 bit representation of 65537
hash: {name: "SHA-256"}
},
true, // can extract it later if we want
["sign", "verify"]
).then(function(keyPair){
log('Exporting from keyPair', keyPair)
subtleCrypto.exportKey('pkcs8', keyPair.privateKey).then(function(pkcs8) {
log('Exported keypair!', pkcs8)
}, function(reason) {
log('Couldnt export keypair', reason)
})
}, function(reason){
log('could not generate key', reason)
})
On Chrome and Firefox, the code works fine, printing:
"Exporting from keyPair" Object { privateKey: CryptoKey, publicKey: CryptoKey }
"Exported keypair!" ArrayBuffer { byteLength: 1218 }
However on Safari it fails, printing only:
Exporting from keyPair KeyPair
And then not doing anything. How can I export the key on Safari?