-
Notifications
You must be signed in to change notification settings - Fork 183
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
Issue when encrypt using RSA_OAEP_256 and A256GCM #220
Comments
Hi @frankl1m , your Checkout docs: https://github.com/dvsekhvalnov/jose-jwt#rsa--key-management-family-of-algorithms Your easiest option is to use |
private static RSA rsa = null;
i have this code, all on encryption is OK, when i try decode the same string encoded before, always get same Exception System.Security.Cryptography.CryptographicException: 'Invalid key to use in the specified state. |
Hey @frankl1m , did you export private key? To decode encrypted payload you need private part of keypair. Typically when exporting |
The certificate used only have Public Key, so if RSA.ToXmlString(true) get exception |
@frankl1m you can't decrypt with public key only. You need private key to do it. |
public static string EncodeJWE(string body)
{
string spki = "-----BEGIN PUBLIC KEY-----\nENCODED PUBLIC KEY\n-----END PUBLIC KEY-----".Replace("\n-----END PUBLIC KEY-----", "").Replace("-----BEGIN PUBLIC KEY-----\n", "");
JweRecipient r3 = new JweRecipient(JweAlgorithm.RSA_OAEP_256,Convert.FromBase64String(spki));
return JWE.Encrypt(body, new[] { r3 }, JweEncryption.A256GCM);
}
When i try to encrypt always i have only public Key, but always i get System.ArgumentException: 'RsaKeyManagement algorithm expects key to be of CngKey, RSACryptoServiceProvider, RSA types or Jwk type with kty='rsa'.' I am using Netfx 4.7.2
The text was updated successfully, but these errors were encountered: