Visa Developer Community

Regular Visitor

JWE in C#

Hi All,

 

I am working on a simple app to use the Visa Token Service Api's. The bit I am really batteling with is building a method were I can pass a string object and encode it as a JWE.

 

From the doc:

Required) BLOB field (URL safe base 64 encoded ) that represents the encrypted payload for payment instrument. (See Encrypted
Payment Instrument .)
JSON Web Encryption using shared secret made available at time of onboarding,
Encrypted Blob of all Payment instrument details.

There is mention of a Java SDK that has a method to create the JWE blob, I need a similar method but in C# to do this. 

 

The .net samples on github for Visa does not include an example of this 😞 

 

Any help on creating/implementing this method would be greatly appreciated. 

 

Thank you so much!

4 REPLIES 4
Community Manager

Re: JWE in C#

Hi WillieBurgerICS, 

 

I am working to get this for you.

 

Thanks,

Ricardo 

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

Re: JWE in C#

Hi Ricardo,
Thank you 🙂
Please note that I have gone through all the samples on the GitHub repo including all the C# unit tests for the api's.
None of these API's include the JWE bit.
Kind Regards
Willie
Regular Visitor

Re: JWE in C#

Hi Riccardo,

 

From the documentation we got this far:

 

public static string JWEEncode(string message,string key, string secret)
{
HMACSHA256 hmacsha256 = new HMACSHA256();

var test = hmacsha256.ComputeHash(new ASCIIEncoding().GetBytes(secret));
var extraHeaders = new Dictionary<string, object>();
extraHeaders.Add("kid", key);

string result = Jose.JWT.Encode(message, test, JweAlgorithm.A256GCMKW, JweEncryption.A256CBC_HS512,extraHeaders: extraHeaders);

return result;
}

 

the Key and the secret are passed from the values in the devloper portal sandbo environment.

 

We are using the JOSE JWT library found here: 

https://github.com/dvsekhvalnov/jose-jwt

 

However we still get a result:

{"errorResponse":{"status":400,"message":"Input is invalid or inconsistent with the profile.","reason":"invalidParameter","details":[{"location":"clientAppID"}]}}

 

The unencrypted message we are passing is:

{"accountNumber": "4411059860000004",  "name": "BillEvans","cvv2":"123","expirationDate": {"month": "10","year": "2015"},"billingAddress": {    "line1": "801MetroCenterBlvd","line2": null,"city": "FosterCity","state": "CA","country": "US","postalCode": "94404"}}

 

The RAW request:

{
"clientAppID": "APP1",
"locale": "en_US",
"panSource": "MOBILEAPP",
"encPaymentInstrument": "eyJhbGciOiJBMjU2R0NNS1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwia2lkIjoiSEc2MUM0UURMV1ZGU002TjFZQkgyMXJkZ1BqNVpzRTNHOTZPUFJ4REpLT1R6ejVJayIsIml2IjoieGI0eHEyR2hvaDlSbnNPVSIsInRhZyI6ImRVeHNBRDV2ZURuWVdhaXF5ZXpCNWcifQ.MaQVGt6rsucf58ma1kLsRSIPOHPwjdQM6YlhF6WYI8NEtajLXYwzzywvPMtvJB7ef5GIl1Jwy2wT4sMbCmKd0g._nWJK9944KY3kFdMT23IrA.yvc_JUX6leJxi91mgIAEpd2pGIuhXDoGNMYTUfhDFCxwqMbZwbSayOvWwk58ftCnB72HCK3lGkXmw2xkk32Iqbu4NpyLBQXA13969KpX4o2sq65anuHyX2Xg5oZ6EXz8hBzY7_XmnYD4-LYGdkU14dYZcRJ7glZohXP-BrNWhUlM-4n_SQgm1FQIgDjvOrNwSX5QlyWWLQXnO9jAhwrSHricgytDXzEnGa7Xn6Dt3hiEk1Ivpu69C9imXhs11QryLln-Z3ngguyQRpYjOlEv_x7Wx6OapfDRhgelloHu3mqHABQnz-VMgyvl11ZHTwQUVnyKZ42b-7giA97Jl-5cZY35H-pm4lmgDUvSnrxcJKQ5OzXESe1XgaYTDE2uysGU.E_R_1bxSep_yGxgfXAht-u4NWVAL0EJ21OEASUXQt5Y"
}

 

Any help will be greatly appreciated.

Highlighted
Helper

Re: JWE in C#

Hi Recardo,

I am also using same api, but face same issue as it is new for us, can you please post sample code in github.

 

Thank you