Object Creation
To create a securestore object, load the @brightsign/securestore module using the Node.js® require() method:
Code Block | ||
---|---|---|
| ||
var securestoreClass = require("@brightsign/securestore"); var securestore = new securestoreClass(); |
SecureStore
writePkcs8DecryptionKey()
Code Block | ||
---|---|---|
| ||
Promise<void> writePkcs8DecryptionKey(String name, Array<byte> data) |
Writes the key in pkcs8 format to the securestore.
[String] namename
string: The filename of the key within the secure store.[data
Array] data: The key as a Uint8 data array.
decryptWithPkcs8Key()
Code Block | ||
---|---|---|
| ||
Promise<Array<byte>> decryptWithPkcs8Key(String name, String algorithm, String hash, Array<byte> data) |
Decrypts a data array using the designated key stored in the securestore and using the designated algorithm and hash.
[String] name:
name
string: The filename of the key within the secure store.[String] algorithm:
Foralgorithm
string: For the moment, the only algorithm supported is ""RSA-OAEP".[String] hash:
Hashhash
string: Hash values can be any of the following: "SHA-1", "SHA-256", "SHA-384" or "SHA-512".[data
Array] data: Uint8Array data
eraseSecureStore()
Code Block | ||
---|---|---|
| ||
Promise<void> eraseSecureStore() |
Completely deletes the securestore.
Examples
Write example:
Code Block | ||
---|---|---|
| ||
window.crypto.subtle.generateKey( { name: "RSA-OAEP", modulusLength: 2048, //can be 1024, 2048, or 4096 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), hash: {name: "SHA-1"}, //can be "SHA-1", "SHA-256", "SHA-384", or "SHA-512" }, true, //whether the key is extractable (i.e. can be used in exportKey) ["encrypt", "decrypt"] //must be ["encrypt", "decrypt"] or ["wrapKey", "unwrapKey"] ) .then(function(key){ window.crypto.subtle.exportKey("pkcs8", key.privateKey) .then(function(exportKey) { var SecureClass = require("@brightsign/securestore"); var secure = new SecureClass(); secure.write("testkey.bin", Array.from(new Uint8Array(exportKey))) .then(function(store){ .... } .... }); |
Decrypt example:
Code Block | ||
---|---|---|
| ||
var SecureClass = require("@brightsign/securestore"); var secure = new SecureClass(); decryptWithPkcs8Key("testkey.bin", "RSA-OAEP", "SHA-1", Array.from(new Uint8Array(encrypted))) .then(function(decryptedArray){ .... }) |
Delete example:
Code Block | ||
---|---|---|
| ||
var SecureClass = require("@brightsign/securestore"); var secure = new SecureClass(); secure.eraseSecureStore() |