encryptCard function
Implementation
String encryptCard({
required String cardNumber,
required String cardHolderName,
required String cardSecurityCode,
required String cardExpMonth,
required String cardExpYear,
required String publicKey,
}) {
final encrypter = getEncrypter(
'''-----BEGIN PUBLIC KEY-----\n
$publicKey
\n-----END PUBLIC KEY-----''');
if (encrypter == null) {
throw Exception('Invalid public key');
}
final pan = formatToString(cardNumber);
final holder = trunkString(cardHolderName, 30);
final securityCode = formatToString(cardSecurityCode);
final expMonth = formatExpMonth(cardExpMonth);
final expYear = formatToString(cardExpYear);
final timestamp = DateTime.now().millisecondsSinceEpoch;
final data = '$pan;$securityCode;$expMonth;$expYear;$holder;$timestamp';
final encryptedData = encrypter.encrypt(data);
return encryptedData.base64;
}