Class: PrivateKeyStorage

PrivateKeyStorage

new PrivateKeyStorage()

PrivateKeyStorage is an abstract class which declares methods for working with a private key storage. You should use a subclass.
Source:

Methods

(static) bigIntegerToBuffer(bigInteger) → {Buffer}

Convert a BigInteger to a Buffer.
Parameters:
Name Type Description
bigInteger BigInteger The BigInteger.
Source:
Returns:
The Buffer.
Type
Buffer

(static) encodePkcs1PrivateKeyFromRSAKey(rsaKey) → {Blob}

Encode the RSAKey private key as a PKCS #1 private key.
Parameters:
Name Type Description
rsaKey RSAKey The RSAKey private key.
Source:
Returns:
The PKCS #1 private key DER.
Type
Blob

(static) encodePkcs8PrivateKey(privateKeyDer, oid, parameters) → {Blob}

Encode the private key to a PKCS #8 private key. We do this explicitly here to avoid linking to extra OpenSSL libraries.
Parameters:
Name Type Description
privateKeyDer Buffer The input private key DER.
oid OID The OID of the privateKey.
parameters DerNode The DerNode of the parameters for the OID.
Source:
Returns:
The PKCS #8 private key DER.
Type
Blob

(static) encodePublicKeyFromRSAKey(rsaKey) → {Blob}

Encode the public key values in the RSAKey private key as a SubjectPublicKeyInfo.
Parameters:
Name Type Description
rsaKey RSAKey The RSAKey private key with the public key values.
Source:
Returns:
The SubjectPublicKeyInfo DER.
Type
Blob

decrypt(keyName, data, isSymmetric) → {Blob}

Decrypt data.
Parameters:
Name Type Description
keyName Name The name of the decrypting key.
data Buffer The byte to be decrypted.
isSymmetric boolean (optional) If true symmetric encryption is used, otherwise asymmetric encryption is used. If omitted, use asymmetric encryption.
Source:
Returns:
The decrypted data.
Type
Blob

deleteKeyPair(keyName)

Delete a pair of asymmetric keys. If the key doesn't exist, do nothing.
Parameters:
Name Type Description
keyName Name The name of the key pair.
Source:
Throws:
Error If deleteKeyPairPromise doesn't return a SyncPromise which is already fulfilled.

deleteKeyPairPromise(keyName, useSync) → {Promise|SyncPromise}

Delete a pair of asymmetric keys. If the key doesn't exist, do nothing.
Parameters:
Name Type Description
keyName Name The name of the key pair.
useSync boolean (optional) If true then return a SyncPromise which is already fulfilled. If omitted or false, this may return a SyncPromise or an async Promise.
Source:
Returns:
A promise that fulfills when the key pair is deleted.
Type
Promise | SyncPromise

doesKeyExist(keyName, keyClass) → {boolean}

Check if a particular key exists.
Parameters:
Name Type Description
keyName Name The name of the key.
keyClass number The class of the key, e.g. KeyClass.PUBLIC, KeyClass.PRIVATE, or KeyClass.SYMMETRIC.
Source:
Throws:
Error If doesKeyExistPromise doesn't return a SyncPromise which is already fulfilled.
Returns:
True if the key exists.
Type
boolean

doesKeyExistPromise(keyName, keyClass, useSync) → {Promise|SyncPromise}

Check if a particular key exists.
Parameters:
Name Type Description
keyName Name The name of the key.
keyClass number The class of the key, e.g. KeyClass.PUBLIC, KeyClass.PRIVATE, or KeyClass.SYMMETRIC.
useSync boolean (optional) If true then return a SyncPromise which is already fulfilled. If omitted or false, this may return a SyncPromise or an async Promise.
Source:
Returns:
A promise which returns true if the key exists.
Type
Promise | SyncPromise

encrypt(keyName, data, isSymmetric) → {Blob}

Encrypt data.
Parameters:
Name Type Description
keyName Name The name of the encrypting key.
data Buffer The byte to be encrypted.
isSymmetric boolean (optional) If true symmetric encryption is used, otherwise asymmetric encryption is used. If omitted, use asymmetric encryption.
Source:
Returns:
The encrypted data.
Type
Blob

generateKey(keyName, params)

Parameters:
Name Type Description
keyName Name The name of the key.
params KeyParams The parameters of the key.
Source:

generateKeyPair(keyName, params)

Generate a pair of asymmetric keys.
Parameters:
Name Type Description
keyName Name The name of the key pair.
params KeyParams The parameters of the key.
Source:
Throws:
Error If generateKeyPairPromise doesn't return a SyncPromise which is already fulfilled.

generateKeyPairPromise(keyName, params, (optional)) → {Promise|SyncPromise}

Generate a pair of asymmetric keys.
Parameters:
Name Type Description
keyName Name The name of the key pair.
params KeyParams The parameters of the key.
(optional) boolean useSync If true then return a SyncPromise which is already fulfilled. If omitted or false, this may return a SyncPromise or an async Promise.
Source:
Returns:
A promise that fulfills when the pair is generated.
Type
Promise | SyncPromise

getPublicKey(keyName) → {PublicKey}

Get the public key
Parameters:
Name Type Description
keyName Name The name of public key.
Source:
Throws:
Error If getPublicKeyPromise doesn't return a SyncPromise which is already fulfilled.
Returns:
The public key.
Type
PublicKey

getPublicKeyPromise(keyName, useSync) → {Promise|SyncPromise}

Get the public key
Parameters:
Name Type Description
keyName Name The name of public key.
useSync boolean (optional) If true then return a SyncPromise which is already fulfilled. If omitted or false, this may return a SyncPromise or an async Promise.
Source:
Returns:
A promise that returns the PublicKey.
Type
Promise | SyncPromise

sign(data, keyName, digestAlgorithm) → {Blob}

Fetch the private key for keyName and sign the data to produce a signature Blob.
Parameters:
Name Type Description
data Buffer Pointer to the input byte array.
keyName Name The name of the signing key.
digestAlgorithm number (optional) The digest algorithm from DigestAlgorithm, such as DigestAlgorithm.SHA256. If omitted, use DigestAlgorithm.SHA256.
Source:
Throws:
Error If signPromise doesn't return a SyncPromise which is already fulfilled.
Returns:
The signature Blob.
Type
Blob

signPromise(data, keyName, digestAlgorithm, useSync) → {Promise|SyncPromise}

Fetch the private key for keyName and sign the data to produce a signature Blob.
Parameters:
Name Type Description
data Buffer Pointer to the input byte array.
keyName Name The name of the signing key.
digestAlgorithm number (optional) The digest algorithm from DigestAlgorithm, such as DigestAlgorithm.SHA256. If omitted, use DigestAlgorithm.SHA256.
useSync boolean (optional) If true then return a SyncPromise which is already fulfilled. If omitted or false, this may return a SyncPromise or an async Promise.
Source:
Returns:
A promise that returns the signature Blob.
Type
Promise | SyncPromise