Re: encryption encaddresss and encemailaddress
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
i am trying to call https://sandbox.api.visa.com/universal/core/customers?apikey=Q9MB9U1NC6HE9R0ZNFP621-fmAF07Hj6s60IKkf...
Response :
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();
}
}
Solved! Go to Solution
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: encryption encaddresss and encemailaddress
okay thanks