2

コマンドを使用して次のファイルを作成します。

makecert -n "CN=TEST_CER" -sv "Test.pvk" -r -sky echange -pe test.cer
pvk2pfx -pvk Eltapk.pvk -spc test.cer  -pfx test.pfx -pi PVKPASS -po PFXPASS -f

次に、次のテストアプリケーションでtest.pfxを使用します。

            X509Certificate2 cer2 = new X509Certificate2("test.pfx", "PFXPASS");

            RSACryptoServiceProvider PrivateKey = cer2.PrivateKey as RSACryptoServiceProvider;
            RSACryptoServiceProvider PublicKey = cer2.PublicKey.Key as RSACryptoServiceProvider;

            string test = "test123";
            byte[] testb = Encoding.UTF8.GetBytes(test);

            testb = PublicKey.Encrypt(testb, true);
            testb = PrivateKey.Decrypt(testb, true);
            test = Encoding.UTF8.GetString(testb);

そして、CryptographicException:BadKeyが発生します。

私は-skyexchangeと-peを使用します。

私が間違っていることは何ですか?

PSPrivateKey.Encryptも同じ例外で失敗します

4

0 に答える 0