createEncryptedRequestPayload method

String createEncryptedRequestPayload(
  1. String json,
  2. String base64Cert
)

Public API: generate the final payload JSON string that matches native output { "Encrypted_skey": "<base64 RSA(sessionKey)>", "Encrypted_data": "<base64 AES-ECB-PKCS7(json bytes)>", "Platform": "2" }

Implementation

String createEncryptedRequestPayload(
    String json,
    String base64Cert,
    ) {
  final plainBytes = Uint8List.fromList(utf8.encode(json));
  final aesEncrypted = _aesEcbPkcs7Encrypt(sessionKey, plainBytes);

  final rsaPub = _rsaPublicKeyFromBase64Certificate(base64Cert);
  final rsaEncrypted = _rsaEncryptSessionKey(sessionKey, rsaPub);

  return jsonEncode({
    EnvConfig.jawEncryptionSkey: base64Encode(rsaEncrypted),
    EnvConfig.jawEncryptionData: base64Encode(aesEncrypted),
    EnvConfig.jawPlatform: EnvConfig.panEncryptionPlatform,
  });
}