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.
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.
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 + "\"}";
}