julialiebs
Helper

Decrypted consumer data

Hello,

 

I'm trying to figure out how to decrypt the consumer data after getting V.on("payment.success"....)

I'm using Node.js and I used the decryption algorithm provided in the docs. 

// key = encryption shared secret
// wrappedKey = req.body.encKey
// payload = req.body.encPaymentData 
module.exports = { decryptPayload: function(key,wrappedKey,payload){....} }
 
After this function finishes and I log the decryptedData to the console, I get two arrays full of a bunch of numbers. I know that the HMAC equals the hash, so I think it's functioning correctly, but I cannot find documentation on what these numbers mean or how to proceed. What comes next, where do I pass that data?  
 
the first buffer returned from using the key and wrappedKey looks like:
Buffer(32) [166, 98, 34, 246, 34, 101, 38, 131, 107, 98, 234, 118, 61, 157, 234, 22, 133, 120, 122, 148, 200, 125, 181, 2, 23, 210, 226, 95, 80, 48, 252, 209]
 
the second one (from wrappedKey and payload) is much longer:
Buffer(1777) [123, 34, 112, 97, 121, 109, 101, 110, 116, 82, 101, 113, 117, 101, 115, 116, 34, 58, 123, 34, 99, 117, 114, 114, 101, 110, 99, 121, 67, 111, 100, 101, 34, 58, 34, 85, 83, 68, 34, 44, 34, 115, 117, 98, 116, 111, 116, 97, 108, 34, 58, 34, 49, 48, 34, 125, 44, 34, 117, 115, 101, 114, 68, 97, 116, 97, 34, 58, 123, 34, 117, 115, 101, 114, 70, 105, 114, 115, 116, 78, 97, 109, 101, 34, 58, 34, 74, 117, 108, 105, 97, 34, 44, 34, 117, 115, 101, 114, 76, 97, …]
 
I am using one of the test credit card numbers provided in the getting started documentation. 
Grateful for any help! 
(FYI: This project is for school and learning purposes only, and I have a week to get this implemented!)
 
Thanks,
Julia
6 REPLIES 6
DianaTran-Yee
Visa Developer Support Specialist

Re: Decrypted consumer data

Hey @julialiebs,

 

Can you please confirm the API product that your query relates to so that we can provide you with further assistance?  Please take a look at our website for APIs relevant to your business case. We are happy to help. 
https://developer.visa.com/ 
https://developer.visa.com/apibrowser 

 




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.

julialiebs
Helper

Re: Decrypted consumer data

This is using the Get Payment Info API when decrypting consumer information by using the following sample code:

The following Node.js JavaScript code provides an example of decrypting the payload:

const crypto = require('crypto');
module.exports = { decryptPayload: function(key,wrappedKey,payload){
let decryptedKey = decrypt(wrappedKey,key); let decryptedMsg = decrypt(payload,decryptedKey); return decryptedMsg.toString('utf8'); }}
function decrypt(encrypted,key){ let encryptedBuffer = new Buffer(encrypted,'base64'); // TODO: Check that data(encryptedBuffer) is at least bigger // than HMAC + IV length , i.e. 48 bytes let hmac = new Buffer(32); let iv = new Buffer(16); encryptedBuffer.copy(hmac,0,0,32); encryptedBuffer.copy(iv,0,32,48); let data = Buffer.from(encryptedBuffer).slice(48);
var hash = crypto.createHmac('SHA256', key).update (Buffer.concat([iv,data])).digest(); if(!hmac.equals(hash)){
// TODO: Handle HMAC validation failure
return ''; }
let decipher = crypto.createDecipheriv('aes-256-cbc', crypto.createHash('sha256').update(key).digest(), iv); let decryptedData = Buffer.concat([decipher.update(data), decipher.final()]); return decryptedData;
}
DianaTran-Yee
Visa Developer Support Specialist

Re: Decrypted consumer data

Hey @julialiebs

 

I'm happy to help you get in touch with a Visa Checkout Partner. Currently, you'll have to work with a partner to integrate Visa Checkout into your project. 

 

Please find a list of Partners to integrate with Visa Checkout using this link here: https://globalcheckout.visa.com/visacheckoutPartners  




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.

julialiebs
Helper

Re: Decrypted consumer data

Hi Diana,

Thanks for your response. I'm hoping to not use a partner, since I am not planning on using this to actually process card data, it's just for the learning process. Is there a way to just create this in a sandbox environment?
julialiebs
Helper

Re: Decrypted consumer data

DianaTran-Yee
Visa Developer Support Specialist

Re: Decrypted consumer data

Hey @julialiebs,

 

Please reach out to a Visa Checkout Partner using this link here if you have any questions about Visa Checkout: https://globalcheckout.visa.com/visacheckoutPartners   




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.