0
私はC#dotnet coreでRSAをテストしています。私は2つのRSAオブジェクトを作成します。一つは暗号化用、もう一つは解読用です。最初のrsaオブジェクトから公開鍵をエクスポートし、それを他のオブジェクトにインポートします。 2番目が暗号配列を解読すると、Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException
がスローされます。 コードは以下の通りです:C#でRSAを復号化するときのInternal.Cryptography.CryptoThrowHelper.WindowsCryptographicException
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();
ああ私の神!私はそれを知っている。しかし、コード化すると混乱しました。ありがとうございました! –
@boyangあなたが見つけたことをうれしく思います!あなたは答えとしてそれをマークできますか? – GeorgeChond
ええ、しかし方法。私は新しく、そのようなボタンを見つけられません。 –