diff --git a/examples/import_export/export-ecdh-keys.js b/examples/import_export/export-ecdh-keys.js index e765b40..50b3cf1 100644 --- a/examples/import_export/export-ecdh-keys.js +++ b/examples/import_export/export-ecdh-keys.js @@ -1,26 +1,45 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - const generatedKeyPair = await crypto.subtle.generateKey( - { - name: "ECDH", - namedCurve: "P-256", - }, - true, - ["deriveKey", "deriveBits"] - ); + crypto.subtle + .generateKey( + { + name: "ECDH", + namedCurve: "P-256", + }, + true, + ["deriveKey", "deriveBits"] + ) + .then( + (generatedKeyPair) => { + crypto.subtle.exportKey("pkcs8", generatedKeyPair.privateKey).then( + (exportedPrivateKey) => { + console.log( + "operation successful, exported private key: " + + printArrayBuffer(exportedPrivateKey) + ); + }, + (err) => { + console.error("export private key, got unexpected error: " + err); + } + ); - const exportedPrivateKey = await crypto.subtle.exportKey( - "pkcs8", - generatedKeyPair.privateKey - ); - console.log("exported private key: " + printArrayBuffer(exportedPrivateKey)); - - const exportedPublicKey = await crypto.subtle.exportKey( - "raw", - generatedKeyPair.publicKey - ); - console.log("exported public key: " + printArrayBuffer(exportedPublicKey)); + crypto.subtle.exportKey("raw", generatedKeyPair.publicKey).then( + (exportedPublicKey) => { + console.log( + "operation successful, exported public key: " + + printArrayBuffer(exportedPublicKey) + ); + }, + (err) => { + console.error("export public key, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key generation, got unexpected error: " + err); + } + ); } const printArrayBuffer = (buffer) => { diff --git a/examples/import_export/export-ecdsa-keys.js b/examples/import_export/export-ecdsa-keys.js index f354ba8..5616cc8 100644 --- a/examples/import_export/export-ecdsa-keys.js +++ b/examples/import_export/export-ecdsa-keys.js @@ -1,26 +1,45 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - const generatedKeyPair = await crypto.subtle.generateKey( - { - name: "ECDSA", - namedCurve: "P-256", - }, - true, - ["sign", "verify"] - ); + crypto.subtle + .generateKey( + { + name: "ECDSA", + namedCurve: "P-256", + }, + true, + ["sign", "verify"] + ) + .then( + (generatedKeyPair) => { + crypto.subtle.exportKey("pkcs8", generatedKeyPair.privateKey).then( + (exportedPrivateKey) => { + console.log( + "operation successful, exported private key: " + + printArrayBuffer(exportedPrivateKey) + ); + }, + (err) => { + console.error("export private key, got unexpected error: " + err); + } + ); - const exportedPrivateKey = await crypto.subtle.exportKey( - "pkcs8", - generatedKeyPair.privateKey - ); - console.log("exported private key: " + printArrayBuffer(exportedPrivateKey)); - - const exportedPublicKey = await crypto.subtle.exportKey( - "raw", - generatedKeyPair.publicKey - ); - console.log("exported public key: " + printArrayBuffer(exportedPublicKey)); + crypto.subtle.exportKey("raw", generatedKeyPair.publicKey).then( + (exportedPublicKey) => { + console.log( + "operation successful, exported public key: " + + printArrayBuffer(exportedPublicKey) + ); + }, + (err) => { + console.error("export public key, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("got unexpected error: " + err); + } + ); } const printArrayBuffer = (buffer) => { diff --git a/examples/import_export/import-ecdh-key.js b/examples/import_export/import-ecdh-key.js index ad56878..526b00e 100644 --- a/examples/import_export/import-ecdh-key.js +++ b/examples/import_export/import-ecdh-key.js @@ -1,7 +1,7 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - const aliceKeyPair = await importKeys( + importKeys( new Uint8Array([ 4, 8, 249, 89, 225, 84, 28, 108, 246, 144, 7, 182, 109, 32, 155, 16, 102, 22, 66, 253, 148, 220, 48, 6, 106, 21, 123, 98, 229, 191, 20, 200, 35, 5, @@ -18,46 +18,74 @@ export default async function () { 208, 131, 136, 154, 125, 18, 20, 202, 231, 168, 184, 127, 53, 186, 6, 136, 114, 101, 127, 109, 179, 44, 96, 108, 193, 126, 217, 131, 163, 131, 135, ]) - ); + ).then( + (aliceKeyPair) => { + importKeys( + new Uint8Array([ + 4, 218, 134, 37, 137, 90, 68, 101, 112, 234, 68, 87, 110, 182, 85, + 178, 161, 106, 223, 50, 150, 9, 155, 68, 191, 51, 138, 185, 186, 226, + 211, 25, 203, 96, 193, 213, 68, 7, 181, 238, 52, 154, 113, 56, 76, 86, + 44, 245, 128, 194, 103, 14, 81, 229, 124, 189, 13, 252, 138, 98, 196, + 218, 39, 34, 42, + ]), + new Uint8Array([ + 48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, + 42, 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 59, + 168, 213, 160, 115, 123, 19, 203, 62, 86, 50, 152, 17, 210, 42, 35, + 174, 230, 191, 11, 65, 239, 223, 130, 73, 53, 161, 46, 9, 210, 50, 4, + 161, 68, 3, 66, 0, 4, 218, 134, 37, 137, 90, 68, 101, 112, 234, 68, + 87, 110, 182, 85, 178, 161, 106, 223, 50, 150, 9, 155, 68, 191, 51, + 138, 185, 186, 226, 211, 25, 203, 96, 193, 213, 68, 7, 181, 238, 52, + 154, 113, 56, 76, 86, 44, 245, 128, 194, 103, 14, 81, 229, 124, 189, + 13, 252, 138, 98, 196, 218, 39, 34, 42, + ]) + ).then( + (bobKeyPair) => { + // Derive shared secret for Alice + deriveSharedSecret( + aliceKeyPair.privateKey, + bobKeyPair.publicKey + ).then( + (aliceSharedSecret) => { + console.log( + "operation successful, alice shared secret: " + + printArrayBuffer(aliceSharedSecret) + ); + }, + (err) => { + console.error( + "deriving alice shared secret, got unexpected error: " + err + ); + } + ); - const bobKeyPair = await importKeys( - new Uint8Array([ - 4, 218, 134, 37, 137, 90, 68, 101, 112, 234, 68, 87, 110, 182, 85, 178, - 161, 106, 223, 50, 150, 9, 155, 68, 191, 51, 138, 185, 186, 226, 211, 25, - 203, 96, 193, 213, 68, 7, 181, 238, 52, 154, 113, 56, 76, 86, 44, 245, - 128, 194, 103, 14, 81, 229, 124, 189, 13, 252, 138, 98, 196, 218, 39, 34, - 42, - ]), - new Uint8Array([ - 48, 129, 135, 2, 1, 0, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, - 134, 72, 206, 61, 3, 1, 7, 4, 109, 48, 107, 2, 1, 1, 4, 32, 59, 168, 213, - 160, 115, 123, 19, 203, 62, 86, 50, 152, 17, 210, 42, 35, 174, 230, 191, - 11, 65, 239, 223, 130, 73, 53, 161, 46, 9, 210, 50, 4, 161, 68, 3, 66, 0, - 4, 218, 134, 37, 137, 90, 68, 101, 112, 234, 68, 87, 110, 182, 85, 178, - 161, 106, 223, 50, 150, 9, 155, 68, 191, 51, 138, 185, 186, 226, 211, 25, - 203, 96, 193, 213, 68, 7, 181, 238, 52, 154, 113, 56, 76, 86, 44, 245, - 128, 194, 103, 14, 81, 229, 124, 189, 13, 252, 138, 98, 196, 218, 39, 34, - 42, - ]) - ); - - console.log("alice: ", JSON.stringify(aliceKeyPair)); - console.log("bob: ", JSON.stringify(bobKeyPair)); - - // Derive shared secret for Alice - const aliceSharedSecret = await deriveSharedSecret( - aliceKeyPair.privateKey, - bobKeyPair.publicKey - ); - - // Derive shared secret for Bob - const bobSharedSecret = await deriveSharedSecret( - bobKeyPair.privateKey, - aliceKeyPair.publicKey + // Derive shared secret for Bob + deriveSharedSecret( + bobKeyPair.privateKey, + aliceKeyPair.publicKey + ).then( + (bobSharedSecret) => { + console.log( + "operation successful, bob shared secret: " + + printArrayBuffer(bobSharedSecret) + ); + }, + (err) => { + console.error( + "deriving bob shared secret, got unexpected error: " + err + ); + } + ); + }, + (err) => { + console.error("importing bob keys, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("importing alice keys, got unexpected error: " + err); + } ); - - console.log("alice shared secret: " + printArrayBuffer(aliceSharedSecret)); - console.log("bob shared secret: " + printArrayBuffer(bobSharedSecret)); } const importKeys = async (publicKeyData, privateKeyData) => { @@ -84,10 +112,10 @@ async function deriveSharedSecret(privateKey, publicKey) { return crypto.subtle.deriveBits( { name: "ECDH", - public: publicKey, // An ECDH public key from the other party + public: publicKey, }, - privateKey, // Your ECDH private key - 256 // the number of bits to derive + privateKey, + 256 ); } diff --git a/examples/import_export/import-ecdsa-keys.js b/examples/import_export/import-ecdsa-keys.js index c2443f2..d2d484e 100644 --- a/examples/import_export/import-ecdsa-keys.js +++ b/examples/import_export/import-ecdsa-keys.js @@ -1,7 +1,7 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - const aliceKeyPair = await importKeys( + importKeys( new Uint8Array([ 4, 106, 149, 34, 76, 184, 103, 101, 35, 234, 57, 76, 231, 21, 188, 244, 15, 179, 101, 113, 24, 6, 17, 21, 195, 60, 181, 73, 154, 170, 206, 21, @@ -20,9 +20,16 @@ export default async function () { 233, 76, 31, 135, 131, 215, 123, 149, 171, 153, 231, 152, 197, 87, 176, 32, 39, 137, ]) + ).then( + (keyPair) => { + console.log( + "operation successful, imported keys" + JSON.stringify(keyPair) + ); + }, + (err) => { + console.error("importing keys, got unexpected error: " + err); + } ); - - console.log("alice: ", JSON.stringify(aliceKeyPair)); } const importKeys = async (publicKeyData, privateKeyData) => { diff --git a/examples/import_export/import-export-aes-key.js b/examples/import_export/import-export-aes-key.js index d2ee621..e4b2e47 100644 --- a/examples/import_export/import-export-aes-key.js +++ b/examples/import_export/import-export-aes-key.js @@ -1,24 +1,45 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - const generatedKey = await crypto.subtle.generateKey( - { - name: "AES-CBC", - length: "256", - }, - true, - ["encrypt", "decrypt"] - ); - - const exportedKey = await crypto.subtle.exportKey("raw", generatedKey); - - const importedKey = await crypto.subtle.importKey( - "raw", - exportedKey, - "AES-CBC", - true, - ["encrypt", "decrypt"] - ); - - console.log(JSON.stringify(importedKey)); + crypto.subtle + .generateKey( + { + name: "AES-CBC", + length: "256", + }, + true, + ["encrypt", "decrypt"] + ) + .then( + (key) => { + // export key + crypto.subtle.exportKey("raw", key).then( + (exportedKey) => { + // try to import the key again + crypto.subtle + .importKey("raw", exportedKey, "AES-CBC", true, [ + "encrypt", + "decrypt", + ]) + .then( + (importedKey) => { + console.log( + "operation successful, imported: " + + JSON.stringify(importedKey) + ); + }, + (err) => { + console.error("key import, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key export, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key generation, got unexpected error: " + err); + } + ); } diff --git a/examples/import_export/import-export-hmac-key.js b/examples/import_export/import-export-hmac-key.js index 9eda527..61475bf 100644 --- a/examples/import_export/import-export-hmac-key.js +++ b/examples/import_export/import-export-hmac-key.js @@ -1,28 +1,48 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - try { - const generatedKey = await crypto.subtle.generateKey( + crypto.subtle + .generateKey( { name: "HMAC", hash: { name: "SHA-256" }, }, true, ["sign", "verify"] + ) + .then( + (generatedKey) => { + // Export the key + crypto.subtle.exportKey("raw", generatedKey).then( + (exportedKey) => { + // Try to import the key again + crypto.subtle + .importKey( + "raw", + exportedKey, + { name: "HMAC", hash: { name: "SHA-256" } }, + true, + ["sign", "verify"] + ) + .then( + (importedKey) => { + console.log( + "operation successful, imported: " + + JSON.stringify(importedKey) + ); + }, + (err) => { + console.error("importing key, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("exporting key, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key generation, got unexpected error: " + err); + } ); - - const exportedKey = await crypto.subtle.exportKey("raw", generatedKey); - - const importedKey = await crypto.subtle.importKey( - "raw", - exportedKey, - { name: "HMAC", hash: { name: "SHA-256" } }, - true, - ["sign", "verify"] - ); - - console.log(JSON.stringify(importedKey)); - } catch (err) { - console.log(JSON.stringify(err)); - } } diff --git a/examples/import_export/import-export-jwk-aes-key.js b/examples/import_export/import-export-jwk-aes-key.js index 0d4f494..6a2e600 100644 --- a/examples/import_export/import-export-jwk-aes-key.js +++ b/examples/import_export/import-export-jwk-aes-key.js @@ -1,36 +1,55 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - try { - const generatedKey = await crypto.subtle.generateKey( + crypto.subtle + .generateKey( { name: "AES-CBC", length: "256", }, true, ["encrypt", "decrypt"] + ) + .then( + (generatedKey) => { + // first time export + crypto.subtle.exportKey("jwk", generatedKey).then( + (exportedKey) => { + // try to import the key again + crypto.subtle + .importKey("jwk", exportedKey, "AES-CBC", true, [ + "encrypt", + "decrypt", + ]) + .then( + (importedKey) => { + // second time export + crypto.subtle.exportKey("jwk", importedKey).then( + (exportedAgain) => { + console.log( + "operation successful, exported again: " + + JSON.stringify(exportedAgain) + ); + }, + (err) => { + console.error( + "second key export, got unexpected error: " + err + ); + } + ); + }, + (err) => { + console.error("key import, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("first key export, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key generation, got unexpected error: " + err); + } ); - - console.log("generated: " + JSON.stringify(generatedKey)); - - const exportedKey = await crypto.subtle.exportKey("jwk", generatedKey); - - console.log("exported: " + JSON.stringify(exportedKey)); - - const importedKey = await crypto.subtle.importKey( - "jwk", - exportedKey, - "AES-CBC", - true, - ["encrypt", "decrypt"] - ); - - console.log("imported: " + JSON.stringify(importedKey)); - - const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); - - console.log("exported again: " + JSON.stringify(exportedAgain)); - } catch (err) { - console.log(JSON.stringify(err)); - } } diff --git a/examples/import_export/import-export-jwk-aes-static-key.js b/examples/import_export/import-export-jwk-aes-static-key.js index 9634733..c6426ab 100644 --- a/examples/import_export/import-export-jwk-aes-static-key.js +++ b/examples/import_export/import-export-jwk-aes-static-key.js @@ -1,31 +1,34 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - try { - const jwk = { - alg: "A256CBC", - ext: true, - k: "LhR2VJFb1NJ8HORgOn7LNKLXhUqPsTjC65UAWFb4GKI", - key_ops: ["encrypt", "decrypt"], - kty: "oct", - }; + const jwk = { + alg: "A256CBC", + ext: true, + k: "LhR2VJFb1NJ8HORgOn7LNKLXhUqPsTjC65UAWFb4GKI", + key_ops: ["encrypt", "decrypt"], + kty: "oct", + }; - console.log("static key: " + JSON.stringify(jwk)); - - const importedKey = await crypto.subtle.importKey( - "jwk", - jwk, - { name: "AES-CBC", length: 256 }, - true, - ["encrypt", "decrypt"] + crypto.subtle + .importKey("jwk", jwk, { name: "AES-CBC", length: 256 }, true, [ + "encrypt", + "decrypt", + ]) + .then( + (importedKey) => { + crypto.subtle.exportKey("jwk", importedKey).then( + (exportedAgain) => { + console.log( + "operation successful, exported: " + JSON.stringify(exportedAgain) + ); + }, + (err) => { + console.error("key export, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key import, got unexpected error: " + err); + } ); - - console.log("imported: " + JSON.stringify(importedKey)); - - const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); - - console.log("exported again: " + JSON.stringify(exportedAgain)); - } catch (err) { - console.log(JSON.stringify(err)); - } } diff --git a/examples/import_export/import-export-jwk-ecdsa.js b/examples/import_export/import-export-jwk-ecdsa.js index 9052ae8..83308c4 100644 --- a/examples/import_export/import-export-jwk-ecdsa.js +++ b/examples/import_export/import-export-jwk-ecdsa.js @@ -9,19 +9,25 @@ export default async function () { d: "APQIdYNoupMPMPdq4FT-XNLOf9osn3am1DbPddZsRAv-YzHHwXKhJHgZPIJRSHvJEmP6UCF_hf9jb1nNVG46tIO0", }; - console.log("static key: " + JSON.stringify(jwk)); - - const importedKey = await crypto.subtle.importKey( - "jwk", - jwk, - { name: "ECDSA", namedCurve: "P-256" }, - true, - ["sign"] - ); - - console.log("imported: " + JSON.stringify(importedKey)); - - const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); - - console.log("exported again: " + JSON.stringify(exportedAgain)); + crypto.subtle + .importKey("jwk", jwk, { name: "ECDSA", namedCurve: "P-256" }, true, [ + "sign", + ]) + .then( + (importedKey) => { + crypto.subtle.exportKey("jwk", importedKey).then( + (exportedAgain) => { + console.log( + "operation successful, exported: " + JSON.stringify(exportedAgain) + ); + }, + (err) => { + console.error("key export, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key import, got unexpected error: " + err); + } + ); } diff --git a/examples/import_export/import-export-jwk-hmac-key.js b/examples/import_export/import-export-jwk-hmac-key.js index aaaf0fd..a6f19b7 100644 --- a/examples/import_export/import-export-jwk-hmac-key.js +++ b/examples/import_export/import-export-jwk-hmac-key.js @@ -1,36 +1,55 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - try { - const generatedKey = await crypto.subtle.generateKey( + crypto.subtle + .generateKey( { name: "HMAC", hash: { name: "SHA-256" }, }, true, ["sign", "verify"] + ) + .then( + (generatedKey) => { + crypto.subtle.exportKey("jwk", generatedKey).then( + (exportedKey) => { + crypto.subtle + .importKey( + "jwk", + exportedKey, + { name: "HMAC", hash: { name: "SHA-256" } }, + true, + ["sign", "verify"] + ) + .then( + (importedKey) => { + crypto.subtle.exportKey("jwk", importedKey).then( + (exportedAgain) => { + console.log( + "operation successful, exported again: " + + JSON.stringify(exportedAgain) + ); + }, + (err) => { + console.error( + "second key export, got unexpected error: " + err + ); + } + ); + }, + (err) => { + console.error("key import, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("first key export, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key generation, got unexpected error: " + err); + } ); - - console.log("generated: " + JSON.stringify(generatedKey)); - - const exportedKey = await crypto.subtle.exportKey("jwk", generatedKey); - - console.log("exported: " + JSON.stringify(exportedKey)); - - const importedKey = await crypto.subtle.importKey( - "jwk", - exportedKey, - { name: "HMAC", hash: { name: "SHA-256" } }, - true, - ["sign", "verify"] - ); - - console.log("imported: " + JSON.stringify(importedKey)); - - const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); - - console.log("exported again: " + JSON.stringify(exportedAgain)); - } catch (err) { - console.log(JSON.stringify(err)); - } } diff --git a/examples/import_export/import-export-jwk-hmac-static-key.js b/examples/import_export/import-export-jwk-hmac-static-key.js index 7334e2a..809d159 100644 --- a/examples/import_export/import-export-jwk-hmac-static-key.js +++ b/examples/import_export/import-export-jwk-hmac-static-key.js @@ -1,31 +1,35 @@ import { crypto } from "k6/x/webcrypto"; export default async function () { - try { - const jwk = { - alg: "HS256", - ext: true, - k: "H6gLp3lw7w27NrPUn00WpcKU-IJojJdNzhL_8F6se2k", - key_ops: ["sign", "verify"], - kty: "oct", - }; + const jwk = { + alg: "HS256", + ext: true, + k: "H6gLp3lw7w27NrPUn00WpcKU-IJojJdNzhL_8F6se2k", + key_ops: ["sign", "verify"], + kty: "oct", + }; - console.log("static key: " + JSON.stringify(jwk)); - - const importedKey = await crypto.subtle.importKey( - "jwk", - jwk, - { name: "HMAC", hash: { name: "SHA-256" } }, - true, - ["sign", "verify"] + crypto.subtle + .importKey("jwk", jwk, { name: "HMAC", hash: { name: "SHA-256" } }, true, [ + "sign", + "verify", + ]) + .then( + (importedKey) => { + crypto.subtle.exportKey("jwk", importedKey).then( + (exportedAgain) => { + console.log( + "operation successful, exported again: " + + JSON.stringify(exportedAgain) + ); + }, + (err) => { + console.error("key export, got unexpected error: " + err); + } + ); + }, + (err) => { + console.error("key import, got unexpected error: " + err); + } ); - - console.log("imported: " + JSON.stringify(importedKey)); - - const exportedAgain = await crypto.subtle.exportKey("jwk", importedKey); - - console.log("exported again: " + JSON.stringify(exportedAgain)); - } catch (err) { - console.log(JSON.stringify(err)); - } } diff --git a/examples/import_export/import-jwk-base64-decrypt.js b/examples/import_export/import-jwk-base64-decrypt.js index 3bffa5f..7764a1e 100644 --- a/examples/import_export/import-jwk-base64-decrypt.js +++ b/examples/import_export/import-jwk-base64-decrypt.js @@ -18,15 +18,16 @@ export default async function () { k: "9Id_8iG6FkGOWmc1S203vGVnTExtpDGxdQN7v7OV9Uc", }; - try { - const result = await decrypt(jwkKeyData, transmittedData); - - // should output decrypted message - // INFO[0000] result: 'my secret message' source=console - console.log("result: '" + result + "'"); - } catch (e) { - console.log("Error: " + JSON.stringify(e)); - } + decrypt(jwkKeyData, transmittedData).then( + (result) => { + // should output decrypted message + // INFO[0000] operation successful, result: 'my secret message' source=console + console.log("operation successful, result: '" + result + "'"); + }, + (err) => { + console.error("decryption failed, got unexpected error: " + err); + } + ); } const decrypt = async (keyData, transmittedData) => { diff --git a/examples/import_export/import-raw-base64-decrypt.js b/examples/import_export/import-raw-base64-decrypt.js index a74bc58..fe21490 100644 --- a/examples/import_export/import-raw-base64-decrypt.js +++ b/examples/import_export/import-raw-base64-decrypt.js @@ -15,15 +15,16 @@ export default async function () { 69, 215, 55, 197, 43, 122, 160, 178, 228, 104, 4, 115, 138, 159, 119, 49, ]); - try { - const result = await decrypt(keyData, transmittedData); - - // should output decrypted message - // INFO[0000] result: 'my secret message' source=console - console.log("result: '" + result + "'"); - } catch (e) { - console.log("Error: " + JSON.stringify(e)); - } + decrypt(keyData, transmittedData).then( + (result) => { + // should output decrypted message + // INFO[0000] operation successful, result: 'my secret message' source=console + console.log("operation successful, result: '" + result + "'"); + }, + (err) => { + console.error("decryption failed, got unexpected error: " + err); + } + ); } const decrypt = async (keyData, transmittedData) => {