encryptAtKeysWithSelfEncKey method
- @Deprecated('legacy helpers for serialization, if we need to retain this turn it into a static helper')
Future<String>
encryptAtKeysWithSelfEncKey(
- AtKeys atKeys,
- PkamAuthMode authMode,
- String atsign
)
Implementation
@Deprecated(
'legacy helpers for serialization, if we need to retain this turn it into a static helper')
Future<String> encryptAtKeysWithSelfEncKey(
AtKeys atKeys, PkamAuthMode authMode, String atsign) async {
Map<String, dynamic> atKeysMap = {};
if (atKeys.defaultSelfEncryptionKey == null) {
throw AtException('selfEncryptionKey is required to encrypt the atKeys');
}
var atChops = AtChopsImpl(AtChopsKeys()
..selfEncryptionKey =
AESKey(atKeys.defaultSelfEncryptionKey!.toString()));
atKeysMap[auth_constants.defaultEncryptionPublicKey] =
(await atChops.encryptString(
atKeys.defaultEncryptionPublicKey.toString(),
EncryptionKeyType.aes256,
keyName: 'selfEncryptionKey',
iv: AtChopsUtil.generateIVLegacy()))
.result;
atKeysMap[auth_constants.defaultEncryptionPrivateKey] =
(await atChops.encryptString(
atKeys.defaultEncryptionPrivateKey.toString(),
EncryptionKeyType.aes256,
keyName: 'selfEncryptionKey',
iv: AtChopsUtil.generateIVLegacy()))
.result;
atKeysMap[auth_constants.apkamPublicKey] = (await atChops.encryptString(
atKeys.apkamPublicKey.toString(), EncryptionKeyType.aes256,
keyName: 'selfEncryptionKey', iv: AtChopsUtil.generateIVLegacy()))
.result;
if (authMode == PkamAuthMode.keysFile) {
atKeysMap[auth_constants.apkamPrivateKey] = (await atChops.encryptString(
atKeys.apkamPrivateKey.toString(), EncryptionKeyType.aes256,
keyName: 'selfEncryptionKey', iv: AtChopsUtil.generateIVLegacy()))
.result;
}
atKeysMap[auth_constants.apkamSymmetricKey] =
atKeys.apkamSymmetricKey.toString();
atKeysMap[auth_constants.defaultSelfEncryptionKey] =
atKeys.defaultSelfEncryptionKey.toString();
atKeysMap[AtConstants.enrollmentId] = atKeys.enrollmentId;
atKeysMap[atsign] = atKeys.defaultSelfEncryptionKey.toString();
return jsonEncode(atKeysMap);
}