mle sample "RsaKeyManagement algorithm expects key...."
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
December
December
mle sample "RsaKeyManagement algorithm expects key...."
in the mle sample, i'm gettting this when encoding the jwt "RsaKeyManagement algorithm expects key to be of CngKey or RSACryptoServiceProvider types."
I would think the sample would just work. I'm in vs2015 on .net 4.6.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
December
December
Re: mle sample "RsaKeyManagement algorithm expects key...."
Hi @QRTIT, Thank you for reaching out. An agent will get back to you as soon as possible. Until then, if any community member has information that may be helpful, feel free to reply in this thread.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
December
December
Re: mle sample "RsaKeyManagement algorithm expects key...."
I figured it out. I had to change your sample code. The below seems to be working.
private String getEncryptedPayload(String requestBody)
{
RSA clientCertificate = new X509Certificate2(mleServerPublicCertificate).GetRSAPublicKey();
// Convert RSA to RSACryptoServiceProvider
RSACryptoServiceProvider rsaCryptoServiceProvider = clientCertificate as RSACryptoServiceProvider;
if (rsaCryptoServiceProvider == null)
{
rsaCryptoServiceProvider = new RSACryptoServiceProvider();
rsaCryptoServiceProvider.ImportParameters(clientCertificate.ExportParameters(false));
}
DateTime now = DateTime.UtcNow;
long unixTimeMilliseconds = new DateTimeOffset(now).ToUnixTimeMilliseconds();
IDictionary<string, object> extraHeaders = new Dictionary<string, object>{
{"kid", keyId},{"iat",unixTimeMilliseconds}
};
string token = JWT.Encode(requestBody, rsaCryptoServiceProvider, JweAlgorithm.RSA_OAEP_256, JweEncryption.A128GCM, null, extraHeaders);
return "{\"encData\":\"" + token + "\"}";
}
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
January
January
Re: mle sample "RsaKeyManagement algorithm expects key...."
Thank you for the update and for sharing your solution!