Re: JWS JWE Sample Code - Java

shahreen
Occasional Visitor

JWS JWE Sample Code - Java

hello,

i download JWS JWE Sample Code - Java from visa developer center and try to run the test class, but it failed a...

Not sure is it because i change from original JWEHeader jweHeader = JWEHeader.parse(Base64URL.from(b64EncodedHeader));

to JWEHeader jweHeader = JWEHeader.parse(Base64URL.encode(b64EncodedHeader));
The difference of change is from as it having a compilation error if not change from to encode.
Hope someone will help.

 

java.text.ParseException: Invalid JSON: Unexpected token

eyJraWQiOiIyYzUyMzQ1My1lMzJlLTQ2MTItYTQ2MS0zNmJlYzA3MzU4NGMiLCJjdHkiOiJhcHBsaWNhdGlvblwveG1sIiwidHlwIjoiSk9TRSIsImVuYyI6IkEyNTZHQ00iLCJ0YWciOiJDaFhrWnlfMG5KVXkwaTUzX0RMNHBnIiwiaWF0IjoxNjM5MTIwNjQyMzA0LCJhbGciOiJBMjU2R0NNS1ciLCJpdiI6ImFlekstQmlMQ2hCZkFMWnMifQ at position 258.
at com.nimbusds.jose.util.JSONObjectUtils.parse(JSONObjectUtils.java:75)
at com.nimbusds.jose.JWEHeader.parse(JWEHeader.java:1271)
at com.nimbusds.jose.JWEHeader.parse(JWEHeader.java:1288)
at cms.redpay.api.jwe.EncryptionUtilsTest.createAndDecryptJweTestUsingSharedSecretWithXmlPayload(EncryptionUtilsTest.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

 

 

 

 

 

                    

3 REPLIES 3
SLi
Visa Developer Support Specialist
Visa Developer Support Specialist

Re: JWS JWE Sample Code - Java

Hi @shahreen,

 

Thanks for trying the JWS JWE sample code. Please also download the User Guide from the General Assets of your project dashboard. It has useful information for creating, verifying, and decrypting JWS-JWE.

JwsJweUserGuide.jpg


Best,
Stacey

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

Re: JWS JWE Sample Code - Java

thanks Stacey. I go thru the document.

Meanwhile, having a question on Decrypting a JWE Using RSA:
Is Visa having a sample working java program for encrypt and decrypt? hopefully I can get to refer.

I'm currently try to decrypt follow on the document given, but have stuck on following error:

com.nimbusds.jose.JOSEException: Decryption error
at com.nimbusds.jose.crypto.impl.RSA_OAEP_256.decryptCEK(RSA_OAEP_256.java:123)
at com.nimbusds.jose.crypto.RSADecrypter.decrypt(RSADecrypter.java:278)
at com.nimbusds.jose.JWEObject.decrypt(JWEObject.java:415)
at cms.redpay.api.jwe.RedPayJweUtility.decryptToCardholderInfo(RedPayJweUtility.java:143)
at cms.redpay.api.jwe.RedPayJweUtility.main(RedPayJweUtility.java:65)
Caused by: javax.crypto.BadPaddingException: Decryption error
at sun.security.rsa.RSAPadding.unpadOAEP(Unknown Source)
at sun.security.rsa.RSAPadding.unpad(Unknown Source)
at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:370)
at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:404)
at javax.crypto.Cipher.doFinal(Cipher.java:2168)
at com.nimbusds.jose.crypto.impl.RSA_OAEP_256.decryptCEK(RSA_OAEP_256.java:115)

 

SLi
Visa Developer Support Specialist
Visa Developer Support Specialist

Re: JWS JWE Sample Code - Java

Hi @shahreen,

 

Please check out the tutorial below on how to run Java sample code for message level encryption/decryption and feel free to post questions on the page if you have any.

https://community.developer.visa.com/t5/Message-Level-Encryption/How-to-run-Java-Sample-Code-for-MLE...

 

 


Best,
Stacey

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