Ich teste RSA in C# Dotnet-Core. Ich erstelle zwei RSA-Objekte, eines zum Verschlüsseln und das andere zum Entschlüsseln. Ich exportiere den öffentlichen Schlüssel aus dem ersten RSA-Objekt und importiere ihn für das andere Objekt. Wenn das zweite das Chiffre-Array entschlüsselt, gibt es Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException
. Der Code ist unten:Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException beim Entschlüsseln von RSA in C#
String plainstr = "Hello World";
RSA rsa1 = RSA.Create();
RSA rsa2 = RSA.Create();
rsa1.KeySize = 1024;
rsa2.KeySize = 1024;
byte[] cipherbytes = rsa1.Encrypt(Encoding.ASCII.GetBytes(plainstr), RSAEncryptionPadding.Pkcs1);
//If the parameter is true, it works well. But when I use it in an actual project, I won't pass the private key.
RSAParameters parameters = rsa1.ExportParameters(false);
rsa2.ImportParameters(parameters);
//Exception is here.
byte[] plaintbytes = rsa2.Decrypt(cipherbytes, RSAEncryptionPadding.Pkcs1);
Console.WriteLine(Encoding.ASCII.GetString(plaintbytes));
Console.ReadKey();
Oh mein Gott! Ich weiß es. Aber ich habe nur verwirrt, wenn ich Code, haha. Vielen Dank! –
@boyang froh, dass Sie es gefunden haben! Könnten Sie es bitte als Antwort markieren? – GeorgeChond
ja, aber wie. Ich bin neu und finde keinen solchen Knopf –