encryption encaddresss and encemailaddress

Solved! Go to solution
aminarais
Helper

encryption encaddresss and encemailaddress

Hello, 

i am trying to call https://sandbox.api.visa.com/universal/core/customers?apikey=Q9MB9U1NC6HE9R0ZNFP621-fmAF07Hj6s60IKkf...

{
"lastName": "user",
"firstName": "user",
"locale": "en_US",
 "encAddress":"eyJlbmMiOiJBMjU2R0NNIiwidGFnIjoiWVlIOU9zbEZfcDh3ZzQ0d2pXYjFVZyIsImlhdCI6MTY4ODY1ODkwOTk1NCwiYWxnIjoiQTI1NkdDTUtXIiwiaXYiOiJaSU1BaE40Y1lTbUE5aHY1Iiwia2lkIjoiYjNlMGI2MTctODIzNS00OTg3LTg3OTAtZjUxMmZmZDAwNmFhIn0.j48q0gbYjLqwWzyp7WiEN7SgqOEgtnbnRDwpGswDAzk.I2_eq6_CWu1ydTto.yJFOlB77w7GPa8oje8vs5gFHn3vZEKBhMEHTPZ8m0LQxOkJZEPM3w7QEM1NvRD8_Hf68N_EOmA2h_Ly3K3-TEE9dB4KzG_EL-Q8JkG70TU6Kmwy9KuWupATvzxbvuOxlCMgLiTh7qvUVxyl5iS8lYucj0VAYAHJnkDsq2sbPtYBYUVqszEVQWLkXOr2mVyKNu-2emazJ8DvM4zFS-ZvEZ6JG6VCYJAc2HmZh1HlDq67icy-xt7a_adpHdQ.SdYDN2x-zLJ3Sjr2l_ASxw",
 "encEmailAddress":"eyJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2Iiwia2lkIjoiY2ExOTI0OTUtNGZhZS00MjdkLWIxMjEtNTJjZmE4ZWNkNGFhIn0.T096X7_fneBW6rh-lQHsQth5mZPeqLFy8iwFPi40K3REHvWLX6v7h7WEnI1_9HobVxuS04dL-oy7hZh2S_jJWIntanWaSVt8yfvTzqwRQETtlw38HGv4srlaILjLXl8I-1-ij-4lkzBSfs-Np3ORwKaJhQUC5PtS1q21-OiLCrIpOG7IKovlZb0N2lTyb4oTP2ok3Xwb5gnpBZC80t_qfyCwQxjZVkL8mubsIypVbVWgBfS39JGYHs3eiIr9MDqYfd36EIkAZR_qsst0Ycr0eQHg2vUCJCS1Xvy22stg2AVuurISfJl78zfYfUHXFsyvNKc6-29P5Mc7UjKqyrd_dg._apLi8RHxGyxoR2V.xNlDB3ynfQlVchWvz9Gzdcd1TjdkcfyT_83d4LTp4BBsFS7xfFEZ7ZgP5v66p78.OdpBmalG_gSazvWv_I05Gw"
}
and it respond with error 400
Response :
{
    "errorResponse": {
        "status": 400,
        "reason": "invalidParameter",
        "message": "Invalid input parameter(s)",
        "details": [
            {
                "location": "encEmailAddress",
                "message": "Failed to parse/decrypt the value provided."
            },
            {
                "location": "encAddress",
                "message": "Failed to parse/decrypt the value provided."
            }
        ]
    }
}
X-SERVED-BY-5d6d7f4r2f
X-CORRELATION-ID1688680769_037_210987057_-5d6d7f4r2f_VDP_WS
X-ERROR-ORIGIN9900
X-APP-STATUS400
i am using this code to generate the enc address can you please help me with finding the issue in encrypting
import com.nimbusds.jose.*;
import com.nimbusds.jose.crypto.AESDecrypter;
import com.nimbusds.jose.crypto.AESEncrypter;
import com.nimbusds.jose.crypto.MACSigner;
import com.nimbusds.jose.crypto.MACVerifier;
import com.nimbusds.jwt.EncryptedJWT;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
/**
* @author speerbuc@visa.com
**/
public final class JWEUtilsUsingSharedSecret {
private JWEUtilsUsingSharedSecret() {
}
/**
* Create JWE Using Shared Secret
*
* @param plainText - Plain Text to encrypt
* @param apiKey - Key ID (API Key)
* @param secretSecret - Shared Secret
* @return JWE String in Compact Serialization Format
* @throws Exception
*/
public static String createJwe(String plainText, String apiKey, String
sharedSecret) throws Exception {
JWEHeader.Builder headerBuilder = new
JWEHeader.Builder(JWEAlgorithm.A256GCMKW, EncryptionMethod.A256GCM);
headerBuilder.keyID(apiKey);
headerBuilder.customParam("iat", System.currentTimeMillis());
JWEObject jweObject = new JWEObject(headerBuilder.build(), new
Payload(plainText));
jweObject.encrypt(new AESEncrypter(sha256(sharedSecret)));
return jweObject.serialize();
}
/**
* Decrypt JWE with Shared Secret
*
* @param jwe - JWE String in Compack Serilaization Form
* @param sharedSecret - Shared Secret
* @return - Plain Text
* @throws Exception
*/
public static String decryptJwe(String jwe, String sharedSecret) throws
Exception {
EncryptedJWT encryptedJWT = EncryptedJWT.parse(jwe);
encryptedJWT.decrypt(new AESDecrypter(sha256(sharedSecret)));
return encryptedJWT.getPayload().toString();
}
/**
* Create A SHA256 hash of the input
*
* @param input - String value
* @return - SHA-256 hash in bytes
* @throws NoSuchAlgorithmException
*/
private static byte[] sha256(String input) throws
NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(input.getBytes(StandardCharsets.UTF_8));
return md.digest();
}
}
4 REPLIES 4
API_Products
Visa Developer Support Specialist

Re: encryption encaddresss and encemailaddress

Hi @aminarais,

 

To fix the issue, please refer to my answer in this forum post: https://community.developer.visa.com/t5/Implementation-API-Sample-Code/Field-Level-Encryption-univer... 

There's also a file attachment in that forum post link above: VisaPublicKey_ForEncryption_Sbx_Cert (3).zip

 




Thanks,

Diana H.



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

aminarais
Helper

Re: encryption encaddresss and encemailaddress

Hello,

still not awswered i want to know how to encrypt the address and email above using apikey and shared secret. i 've snet you the whole code above.

i didn't understand what is the use of the cert you attached,

can you please explain the process more because it is ambigious.

API_Products
Visa Developer Support Specialist

Re: encryption encaddresss and encemailaddress

Hi @aminarais,

 

It's the Visa Public Key that you can use for encryption for sandbox testing.  You can use the Visa Developer Center Playground tool for sandbox testing. Here's the link to the VDC Playground tool: https://developer.visa.com/pages/visa-developer-center-playground 

 

Follow the directions and you'll use the .pem file for the Public Key.




Thanks,

Diana H.



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

aminarais
Helper

Re: encryption encaddresss and encemailaddress

okay thanks