encPaymentInstrument JWE encryption example in Java

Highlighted

encPaymentInstrument JWE encryption example in Java

Hi, 

 

I'm currently working on Visa VTS project. It would be really helpful to see some examples of Java code for encPaymentInstrument JWE encryption. Could you please send some examples if you have?

 

Thanks & Regards

2 REPLIES 2
Highlighted
Visa Dev Moderator

Re: encPaymentInstrument JWE encryption example in Java

Hey @Jyothiswaroop,

 

I'm happy to help you. Visa Token Service is a restricted product. Please kindly reach out to developer@visa.com or provide your email address and someone will reach out to you to help you with your Visa Token Service product access request.  

 



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

Thanks,
Diana

Highlighted
Regular Contributor

Re: encPaymentInstrument JWE encryption example in Java

Hi @Jyothiswaroop 

We used the below implementation in JWE construction. You can consider the below code for your JWE implementation.
------
private static
String timeStamp() {
return String.valueOf(System.currentTimeMillis() / 1000L);
}

public String getEncPaymentInstrument(EncryptedPaymentInstrument encryptedPaymentInstrument) {
try {
String encPIString = JSONUtil.toJSON(encryptedPaymentInstrument);
logger.info(encPIString);

MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] digest = md.digest(sharedSecret.getBytes("UTF-8"));

JsonWebEncryption jwe = new JsonWebEncryption();
jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A256GCMKW);
jwe.setIv(digest);

jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_256_GCM);

jwe.setHeader("iat", timeStamp());
jwe.setHeader("channelSecurityContext", "SHARED_SECRET");
jwe.setHeader(HeaderParameterNames.TYPE, "JOSE");

jwe.setKey(new SecretKeySpec(digest, "AES"));
jwe.setKeyIdHeaderValue(apiKey);

jwe.setPayload(encPIString);

String serializedJwe = jwe.getCompactSerialization();
return serializedJwe;

} catch (Exception e) {
logger.error("Exception in getEncPaymentInstrument()", e);
throw new IssuerVTSException(IssuerVTSStatusCode.EnrollPanCardVerificationFailed);
}
}

Regards
Paul