Constructor
new MasterKeyManager(masterKeyFileName, saltFileName)
Parameters:
Name | Type | Description |
---|---|---|
masterKeyFileName |
string | File that stores the encrypted master key |
saltFileName |
string | File that stores the salt for deriving the encryption key from the secret |
Constructs a new master key manager.
- Source:
Classes
Methods
(async) loadOrCreateMasterKey(secret) → {Promise.<void>}
Parameters:
Name | Type | Description |
---|---|---|
secret |
string |
Loads the stored master key or create a new one if none was previously created.
This will calculate a derived key from the secret and then:
- master-key file missing: create a new master-key + file encrypted with this derived key
- master-key file exists: load the master-key from file and decrypt it with this derived key
Function will throw if the secret does not match the already existing master-key file.
- Source:
Returns:
Type: Promise.<void>
unloadMasterKey()
Purges the memory from memory.
- Source:
ensureMasterKeyLoaded()
Ensures, that the master is loaded, if not it throws.
- Source:
(async) changeSecret(oldSecret, newSecret) → {Promise.<void>}
Parameters:
Name | Type | Description |
---|---|---|
oldSecret |
string | |
newSecret |
string |
Changes the secret needed to unlock the master-key.
This can be done with or without a loaded master key. Throws if the oldSecret is wrong.
- Source:
Returns:
Type: Promise.<void>
encryptDataWithMasterKey(data) → {Uint8Array}
Parameters:
Name | Type | Description |
---|---|---|
data |
Uint8Array |
Encrypt data with the master key.
Only works if the master key was previously set.
- Source:
Returns:
Type: Uint8Array
decryptDataWithMasterKey(cypherAndNonce) → {Uint8Array}
Parameters:
Name | Type | Description |
---|---|---|
cypherAndNonce |
Uint8Array | The data to decrypt |
Decrypt data with the master key.
Only works if the master key was previously set.
- Source:
Returns:
Type: Uint8Array