remoteKeyForTypeAndId method

SecureKey remoteKeyForTypeAndId(
  1. String type,
  2. int keyId,
  3. int keyLength
)

Generates a SecureKey of keyLength bytes for the given type and keyId.

Internally, this will generate the key based on the master key, the type and the given keyId.

Implementation

SecureKey remoteKeyForTypeAndId(String type, int keyId, int keyLength) {
  SecureKey? repositoryKey;
  try {
    return _repositoryRotKeys[_KeyRotId(type, keyId)] ??=
        sodium.crypto.kdf.deriveFromKey(
      masterKey: repositoryKey = _getRepositoryKey(type),
      context: _repositoryRotationKeyContext,
      subkeyId: keyId,
      subkeyLen: keyLength,
    );
  } finally {
    repositoryKey?.dispose();
  }
}