У меня есть требование создать пару ключей RSA в C#, а затем сохранить ключ publi c в базе данных, который будет использоваться в формате JWK позже.
Но я не могу получить строку из RSAParams.Modulus.
Я пробовал UTF8, UTF32 и общую кодировку, но все еще не отображается.
Ниже приведен код с сайта MSDN.
try
{
// Create a new RSACryptoServiceProvider object.
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
//Export the key information to an RSAParameters object.
//Pass false to export the public key information or pass
//true to export public and private key information.
RSAParameters RSAParams = RSA.ExportParameters(true);
byte[] modulus = RSAParams.Modulus;
var str = System.Text.Encoding.UTF8.GetString(RSAParams.Modulus);
Console.WriteLine(str);
Console.ReadKey();
}
}
catch (CryptographicException e)
{
//Catch this exception in case the encryption did
// not succeed.
Console.WriteLine(e.Message);
}
Спасибо.