Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jose.EncryptionException: 'Unable to decrypt content or authentication tag do not match #195

Open
Dhazan1 opened this issue Jul 20, 2022 · 3 comments

Comments

@Dhazan1
Copy link

Dhazan1 commented Jul 20, 2022

I'm encrypting, then immediately I'm decrypting, but I keep getting this error.
This is the link to the code write-up https://github.com/Dhazan1/JoseLibraryImplementationInAsp.net/tree/main

@dvsekhvalnov
Copy link
Owner

Thanks, i'll try to run soonish.

@Dhazan1
Copy link
Author

Dhazan1 commented Jul 28, 2022

Thanks, i'll try to run soonish.

Still awaiting your response

@dvsekhvalnov
Copy link
Owner

Hi @Dhazan1 , thanks for reminding me.

Are you sure that you are using correct P-256 curve key? Especially if private d param is really matching public x and y? because it is named kid by some reason in your sample.

When i replaced your key to other one, it perfectly working.

            var publicKey = new Jwk(crv: "P-256",
                 x: "BHId3zoDv6pDgOUh8rKdloUZ0YumRTcaVDCppUPoYgk",
                 y: "g3QIDhaWEksYtZ9OWjNHn9a6-i_P9o5_NrdISP0VWDU"
            );

            var privateKey = new Jwk(crv: "P-256",
                  x: "BHId3zoDv6pDgOUh8rKdloUZ0YumRTcaVDCppUPoYgk",
                  y: "g3QIDhaWEksYtZ9OWjNHn9a6-i_P9o5_NrdISP0VWDU",
                  d: "KpTnMOHEpskXvuXHFCfiRtGUHUZ9Dq5CCcZQ-19rYs4"
               );

            var payload = new Dictionary<string, object>()
                        {
                         {"pan","1234567891234567" },
                         {"exp","1223"}
                        };


            var plain = JsonConvert.SerializeObject(payload);

            Console.WriteLine(plain);

            var encryptedData1 = Jose.JWE.Encrypt(plain, new[] { new JweRecipient(JweAlgorithm.ECDH_ES, publicKey) }, encryption);

            Console.WriteLine(encryptedData1);

           var decryptedDataTest = JWE.Decrypt(encryptedData1, privateKey);

            Console.WriteLine(decryptedDataTest.Plaintext);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants