KeyManager class abstract
An abstract class to generate keys for encryption based on a single master key.
The class already provides most of the logic for that job. The only method that has to be implemented is the loadRemoteMasterKey method to obtain the actual master key.
You can use the PassphraseBasedKeyManager instead to create a key manager that will derive it's master key from a passphrase.
The key generation works as follows:
- A
keyIdis either given or generated from the current time (as reported byclock). The algorithm generates the id as"days since epoch" / 30, which means the id is rotated every 30 days. - A
hashingKeyis derived from themasterKey. - A
subkeyIdis generated from thetypeof the repository. This is done by hashing it usingShortHash.calland the previously generatedhashingKey. To ensure compatibility with the browser, the 64 bit of the hash are split in two 32 bit parts and are x-or-ed with each other. - A
repositoryKeyis derived from themasterKeyusing thesubkeyId. - The actual key is derived from the
repositoryKeyusing thekeyId.
All key derivations make use of Kdf.deriveFromKey to derive a new key from
the parent key. All derivations use a special context to ensure unique keys.
Note: You can override the type to subkeyId derivation by overriding
subkeyIdForType.
- Implementers
Constructors
- KeyManager({required Sodium sodium, Clock? clock})
- Default constructor.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sodium → Sodium
-
The sodium instance used by the key manager.
final
Methods
-
dispose(
) → void - Disposes the key manager.
-
initialize(
) → Future< void> - Initializes the key manager.
-
loadRemoteMasterKey(
int keyLength) → Future< SecureKey> - Asynchronously loads the master key for the key manager.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remoteKeyForType(
String type, int keyLength) → KeyInfo -
Generates a
SecureKeyofkeyLengthbytes for the giventype. -
remoteKeyForTypeAndId(
String type, int keyId, int keyLength) → SecureKey -
Generates a
SecureKeyofkeyLengthbytes for the giventypeandkeyId. -
subkeyIdForType(
String type) → int -
Derives a key id from a given repository
type. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited