Hello! i'm trying to execute the Universal Card Enrollment to get the vcardID but i'm having this error:
{"errorResponse":{"status":400,"reason":"invalidParameterEncCard","message":"Invalid input parameter(s)","details":[{"location":"encCard","message":"Unable to parse or decrypt"}]}}
this is how i encrypt the data:
package com.example.chatbot;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.nimbusds.jose.*;
import com.nimbusds.jose.crypto.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.io.FileInputStream;
import java.security.PublicKey;
import java.security.Security;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPublicKey;
@SpringBootApplication
public class ChatBotApplication {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
String filePath = "VisaPublicKey_ForEncryption_Sbx_Cert.pem";
PublicKey publicKey = loadPublicKeyFromCertificate(filePath);
// Object to encrypt
String jsonObject = "{\"accountNumber\":\"V514231274459132\",\"nameOnCard\":\"Cody Payne\",\"cvv2\":\"123\",\"expirationDate\":{\"month\":\"12\",\"year\":\"2030\"},\"billingAddress\":{\"name\":\"Cody Payne\",\"line1\":\"389 North\",\"line2\":\"Mango\",\"line3\":\"Avenue\",\"city\":\"Buffalo\",\"state\":\"OR\",\"countryCode\":\"US\",\"postalCode\":\"04009\"}}";
// Encrypt the object using JWE
String encryptedData = encryptWithJWE(publicKey, jsonObject);
// Print the encrypted data
System.out.println("Encrypted Object: " + encryptedData);
}
public static PublicKey loadPublicKeyFromCertificate(String certificateFilePath) throws Exception {
try (FileInputStream fis = new FileInputStream(certificateFilePath)) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) cf.generateCertificate(fis);
return certificate.getPublicKey();
}
}
public static String encryptWithJWE(PublicKey publicKey, String data) throws Exception {
JWEHeader header = new JWEHeader(JWEAlgorithm.RSA_OAEP_256, EncryptionMethod.A128GCM);
Payload payload = new Payload(data);
JWEObject jweObject = new JWEObject(header, payload);
// Encrypt the JWE with the public key
jweObject.encrypt(new RSAEncrypter((RSAPublicKey) publicKey));
// Serialize to compact format
return jweObject.serialize();
}
}
is this code wrong?
Solved! Go to Solution
Hi @kaoutar, Thank you for reaching out! One of our agents will look into this and get back to you soon. Until then, if any community members know a solution, feel free to reply to this thread.
Hi @kaoutar,
Refer to answer in this forum post here: https://community.developer.visa.com/t5/Implementation-API-Sample-Code/Field-Level-Encryption-univer...