Fix for crypto webkit prefix

This commit is contained in:
Alan Friedman 2016-01-23 21:24:50 -05:00
parent 164c33f893
commit 557a22a01e

View File

@ -107,7 +107,7 @@ $(function() {
}; };
return Promise.all([ return Promise.all([
exportKey(data[0].publicKey), exportKey(data[0].publicKey),
exportKey(data[1].publicKey), exportKey(data[1].publicKey)
]); ]);
}) })
.then(function(exportedKeys) { .then(function(exportedKeys) {
@ -588,7 +588,7 @@ $(function() {
} }
function createSigningKeys() { function createSigningKeys() {
return crypto.subtle.generateKey( return cryptoSubtle.generateKey(
{ {
name: "RSASSA-PKCS1-v1_5", name: "RSASSA-PKCS1-v1_5",
modulusLength: 2048, //can be 1024, 2048, or 4096 modulusLength: 2048, //can be 1024, 2048, or 4096
@ -601,7 +601,7 @@ $(function() {
} }
function createPrimaryKeys() { function createPrimaryKeys() {
return crypto.subtle.generateKey( return cryptoSubtle.generateKey(
{ {
name: "RSA-OAEP", name: "RSA-OAEP",
modulusLength: 2048, //can be 1024, 2048, or 4096 modulusLength: 2048, //can be 1024, 2048, or 4096
@ -614,7 +614,7 @@ $(function() {
} }
function createSecretKey() { function createSecretKey() {
return crypto.subtle.generateKey( return cryptoSubtle.generateKey(
{ {
name: "AES-CBC", name: "AES-CBC",
length: 256, //can be 128, 192, or 256 length: 256, //can be 128, 192, or 256
@ -626,7 +626,7 @@ $(function() {
function encryptSecretKey(data, secretKey) { function encryptSecretKey(data, secretKey) {
// Secret key will be recipient's public key // Secret key will be recipient's public key
return crypto.subtle.encrypt( return cryptoSubtle.encrypt(
{ {
name: "RSA-OAEP" name: "RSA-OAEP"
}, },
@ -637,7 +637,7 @@ $(function() {
function decryptSecretKey(data, key) { function decryptSecretKey(data, key) {
// key will be my private key // key will be my private key
return crypto.subtle.decrypt( return cryptoSubtle.decrypt(
{ {
name: "RSA-OAEP", name: "RSA-OAEP",
//label: Uint8Array([...]) //optional //label: Uint8Array([...]) //optional
@ -648,7 +648,7 @@ $(function() {
} }
function encryptMessage(data, secretKey, iv) { function encryptMessage(data, secretKey, iv) {
return crypto.subtle.encrypt( return cryptoSubtle.encrypt(
{ {
name: "AES-CBC", name: "AES-CBC",
//Don't re-use initialization vectors! //Don't re-use initialization vectors!
@ -661,7 +661,7 @@ $(function() {
} }
function decryptMessage(data, secretKey, iv) { function decryptMessage(data, secretKey, iv) {
return crypto.subtle.decrypt( return cryptoSubtle.decrypt(
{ {
name: "AES-CBC", name: "AES-CBC",
iv: iv, //The initialization vector you used to encrypt iv: iv, //The initialization vector you used to encrypt
@ -672,7 +672,7 @@ $(function() {
} }
function importSecretKey(jwkData, format) { function importSecretKey(jwkData, format) {
return crypto.subtle.importKey( return cryptoSubtle.importKey(
format || "jwk", //can be "jwk" or "raw" format || "jwk", //can be "jwk" or "raw"
//this is an example jwk key, "raw" would be an ArrayBuffer //this is an example jwk key, "raw" would be an ArrayBuffer
jwkData, jwkData,
@ -686,7 +686,7 @@ $(function() {
function importPrimaryKey(jwkData) { function importPrimaryKey(jwkData) {
// Will be someone's public key // Will be someone's public key
return crypto.subtle.importKey( return cryptoSubtle.importKey(
"jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only) "jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only)
jwkData, jwkData,
{ //these are the algorithm options { //these are the algorithm options
@ -701,14 +701,14 @@ $(function() {
function exportKey(key, format) { function exportKey(key, format) {
// Will be public primary key or public signing key // Will be public primary key or public signing key
return crypto.subtle.exportKey( return cryptoSubtle.exportKey(
format || "jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only) format || "jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only)
key //can be a publicKey or privateKey, as long as extractable was true key //can be a publicKey or privateKey, as long as extractable was true
); );
} }
function importSigningKey(jwkData) { function importSigningKey(jwkData) {
return crypto.subtle.importKey( return cryptoSubtle.importKey(
"jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only) "jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only)
//this is an example jwk key, other key types are Uint8Array objects //this is an example jwk key, other key types are Uint8Array objects
jwkData, jwkData,
@ -723,7 +723,7 @@ $(function() {
function signKey(data, keyToSignWith) { function signKey(data, keyToSignWith) {
// Will use my private key // Will use my private key
return crypto.subtle.sign( return cryptoSubtle.sign(
{ {
name: "RSASSA-PKCS1-v1_5" name: "RSASSA-PKCS1-v1_5"
}, },
@ -734,7 +734,7 @@ $(function() {
function verifyKey(signature, data, keyToVerifyWith) { function verifyKey(signature, data, keyToVerifyWith) {
// Will verify with sender's public key // Will verify with sender's public key
return crypto.subtle.verify( return cryptoSubtle.verify(
{ {
name: "RSASSA-PKCS1-v1_5" name: "RSASSA-PKCS1-v1_5"
}, },