generateProof function
Given a payload
, creates a new AES-256 key and uses that to encrypt
the payload itself.
Implementation
Future<ProofGenerationResult> generateProof(
Object payload,
Uri lcdUrl,
) async {
// Generate the AES key
final aesKey = await KeysHelper.generateAesKey();
// Encrypt the payload
final encryptionData = jsonEncode(payload);
final encryptedPayload = EncryptionHelper.encryptStringWithAes(
encryptionData,
aesKey,
);
// Generate nonce, concatenate with payload and encode
final nonce = KeysHelper.generateRandomNonce(12);
final encodedProof = base64.encode(encryptedPayload + nonce);
// Encrypt the AES key
final rsaKey = await EncryptionHelper.getGovernmentRsaPubKey(lcdUrl);
final encryptedAesKey = EncryptionHelper.encryptBytesWithRsa(
aesKey,
rsaKey.publicKey,
);
final encodedAesKey = base64.encode(encryptedAesKey);
return ProofGenerationResult(
encodedProof: encodedProof,
encodedAesKey: encodedAesKey,
);
}