getEncryptedKeys static method
Implementation
static Future<Map<String, String>> getEncryptedKeys(String atsign) async {
AtsignKey? atsignKeyData = await _keyChainManager.readAtsign(name: atsign);
if (atsignKeyData == null) {
throw AtClientException.message(
"Failed to fetch the keys for the atsign: $atsign");
}
Map<String, String> encryptedAtKeysMap = <String, String>{};
String encryptedPkamPublicKey = EncryptionUtil.encryptValue(
atsignKeyData.pkamPublicKey!, atsignKeyData.selfEncryptionKey!);
encryptedAtKeysMap[BackupKeyConstants.PKAM_PUBLIC_KEY_FROM_KEY_FILE] =
encryptedPkamPublicKey;
String encryptedPkamPrivateKey = EncryptionUtil.encryptValue(
atsignKeyData.pkamPrivateKey!, atsignKeyData.selfEncryptionKey!);
encryptedAtKeysMap[BackupKeyConstants.PKAM_PRIVATE_KEY_FROM_KEY_FILE] =
encryptedPkamPrivateKey;
String encryptedEncryptionPublicKey = EncryptionUtil.encryptValue(
atsignKeyData.encryptionPublicKey!, atsignKeyData.selfEncryptionKey!);
encryptedAtKeysMap[BackupKeyConstants.ENCRYPTION_PUBLIC_KEY_FROM_FILE] =
encryptedEncryptionPublicKey;
String encryptedEncryptionPrivateKey = EncryptionUtil.encryptValue(
atsignKeyData.encryptionPrivateKey!, atsignKeyData.selfEncryptionKey!);
encryptedAtKeysMap[BackupKeyConstants.ENCRYPTION_PRIVATE_KEY_FROM_FILE] =
encryptedEncryptionPrivateKey;
encryptedAtKeysMap[BackupKeyConstants.SELF_ENCRYPTION_KEY_FROM_FILE] =
atsignKeyData.selfEncryptionKey!;
// The atKeys file generated previous to APKAM feature will not have the
// apkam_symmetric_key. Hence adding null check to prevent null-pointer exception.
if (atsignKeyData.apkamSymmetricKey != null) {
encryptedAtKeysMap[BackupKeyConstants.APKAM_SYMMETRIC_KEY_FROM_FILE] =
atsignKeyData.apkamSymmetricKey!;
}
// The atKeys file generated previous to APKAM feature will not have the
// enrollment-id. Hence adding null check to prevent null-pointer exception.
if (atsignKeyData.enrollmentId != null) {
encryptedAtKeysMap[BackupKeyConstants.APKAM_ENROLLMENT_ID_FROM_FILE] =
atsignKeyData.enrollmentId!;
}
return encryptedAtKeysMap;
}