public void Encrypt_Dcrypt_Test() { var keypair = RSAHelper.GenerateKeyPair(); var encrypted = RSAHelper.EncryptAsBase64("hello", keypair.PublicKey); var decrypted = RSAHelper.DecryptFromBase64(encrypted, keypair.PrivateKey); Assert.Equal("hello", decrypted); //pkcs8密钥 var pkcs8 = RSAHelper.PKCS1ToPKCS8(keypair.PrivateKey); var decrypted2 = RSAHelper.DecryptFromBase64(encrypted, pkcs8, keyFormat: RSAKeyFormat.PKCS8); Assert.Equal("hello", decrypted2); }