RSACryptoServiceProvider 类

定义

使用加密服务提供程序 (CSP) 提供的 RSA 算法的实现执行不对称加密和解密。Performs asymmetric encryption and decryption using the implementation of the RSA algorithm provided by the cryptographic service provider (CSP). 此类不能被继承。This class cannot be inherited.

public ref class RSACryptoServiceProvider sealed : System::Security::Cryptography::RSA, System::Security::Cryptography::ICspAsymmetricAlgorithm
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class RSACryptoServiceProvider : System.Security.Cryptography.RSA, System.Security.Cryptography.ICspAsymmetricAlgorithm
type RSACryptoServiceProvider = class
    inherit RSA
    interface ICspAsymmetricAlgorithm
Public NotInheritable Class RSACryptoServiceProvider
Inherits RSA
Implements ICspAsymmetricAlgorithm
继承
RSACryptoServiceProvider
属性
实现

示例

下面的代码示例使用 RSACryptoServiceProvider 类将字符串加密为一个字节数组,然后将这些字节解密回一个字符串。The following code example uses the RSACryptoServiceProvider class to encrypt a string into an array of bytes and then decrypt the bytes back into a string.

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
array<Byte>^ RSAEncrypt( array<Byte>^DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding )
{
   try
   {
      
      //Create a new instance of RSACryptoServiceProvider.
      RSACryptoServiceProvider^ RSA = gcnew RSACryptoServiceProvider;
      
      //Import the RSA Key information. This only needs
      //toinclude the public key information.
      RSA->ImportParameters( RSAKeyInfo );
      
      //Encrypt the passed byte array and specify OAEP padding.  
      //OAEP padding is only available on Microsoft Windows XP or
      //later.  

      array<Byte>^encryptedData = RSA->Encrypt( DataToEncrypt, DoOAEPPadding );
      delete RSA;
      return encryptedData;
   }
   //Catch and display a CryptographicException  
   //to the console.
   catch ( CryptographicException^ e ) 
   {
      Console::WriteLine( e->Message );
      return nullptr;
   }

}

array<Byte>^ RSADecrypt( array<Byte>^DataToDecrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding )
{
   try
   {
      
      //Create a new instance of RSACryptoServiceProvider.
      RSACryptoServiceProvider^ RSA = gcnew RSACryptoServiceProvider;
      
      //Import the RSA Key information. This needs
      //to include the private key information.
      RSA->ImportParameters( RSAKeyInfo );
      
      //Decrypt the passed byte array and specify OAEP padding.  
      //OAEP padding is only available on Microsoft Windows XP or
      //later.  
      
      array<Byte>^decryptedData = RSA->Decrypt( DataToDecrypt, DoOAEPPadding );
      delete RSA;
      return decryptedData;
   }
   //Catch and display a CryptographicException  
   //to the console.
   catch ( CryptographicException^ e ) 
   {
      Console::WriteLine( e );
      return nullptr;
   }

}

int main()
{
   try
   {
      
      //Create a UnicodeEncoder to convert between byte array and string.
      UnicodeEncoding^ ByteConverter = gcnew UnicodeEncoding;
      
      //Create byte arrays to hold original, encrypted, and decrypted data.
      array<Byte>^dataToEncrypt = ByteConverter->GetBytes( "Data to Encrypt" );
      array<Byte>^encryptedData;
      array<Byte>^decryptedData;
      
      //Create a new instance of RSACryptoServiceProvider to generate
      //public and private key data.
      RSACryptoServiceProvider^ RSA = gcnew RSACryptoServiceProvider;
      
      //Pass the data to ENCRYPT, the public key information 
      //(using RSACryptoServiceProvider.ExportParameters(false),
      //and a boolean flag specifying no OAEP padding.
      encryptedData = RSAEncrypt( dataToEncrypt, RSA->ExportParameters( false ), false );
      
      //Pass the data to DECRYPT, the private key information 
      //(using RSACryptoServiceProvider.ExportParameters(true),
      //and a boolean flag specifying no OAEP padding.
      decryptedData = RSADecrypt( encryptedData, RSA->ExportParameters( true ), false );
      
      //Display the decrypted plaintext to the console. 
      Console::WriteLine( "Decrypted plaintext: {0}", ByteConverter->GetString( decryptedData ) );
      delete RSA;
   }
   catch ( ArgumentNullException^ ) 
   {
      
      //Catch this exception in case the encryption did
      //not succeed.
      Console::WriteLine( "Encryption failed." );
   }

}

using System;
using System.Security.Cryptography;
using System.Text;

class RSACSPSample
{

    static void Main()
    {
        try
        {
            //Create a UnicodeEncoder to convert between byte array and string.
            UnicodeEncoding ByteConverter = new UnicodeEncoding();

            //Create byte arrays to hold original, encrypted, and decrypted data.
            byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");
            byte[] encryptedData;
            byte[] decryptedData;

            //Create a new instance of RSACryptoServiceProvider to generate
            //public and private key data.
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {

                //Pass the data to ENCRYPT, the public key information 
                //(using RSACryptoServiceProvider.ExportParameters(false),
                //and a boolean flag specifying no OAEP padding.
                encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(false), false);

                //Pass the data to DECRYPT, the private key information 
                //(using RSACryptoServiceProvider.ExportParameters(true),
                //and a boolean flag specifying no OAEP padding.
                decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(true), false);

                //Display the decrypted plaintext to the console. 
                Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
            }
        }
        catch (ArgumentNullException)
        {
            //Catch this exception in case the encryption did
            //not succeed.
            Console.WriteLine("Encryption failed.");

        }
    }

    public static byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
    {
        try
        {
            byte[] encryptedData;
            //Create a new instance of RSACryptoServiceProvider.
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {

                //Import the RSA Key information. This only needs
                //toinclude the public key information.
                RSA.ImportParameters(RSAKeyInfo);

                //Encrypt the passed byte array and specify OAEP padding.  
                //OAEP padding is only available on Microsoft Windows XP or
                //later.  
                encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
            }
            return encryptedData;
        }
        //Catch and display a CryptographicException  
        //to the console.
        catch (CryptographicException e)
        {
            Console.WriteLine(e.Message);

            return null;
        }

    }

    public static byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
    {
        try
        {
            byte[] decryptedData;
            //Create a new instance of RSACryptoServiceProvider.
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                //Import the RSA Key information. This needs
                //to include the private key information.
                RSA.ImportParameters(RSAKeyInfo);

                //Decrypt the passed byte array and specify OAEP padding.  
                //OAEP padding is only available on Microsoft Windows XP or
                //later.  
                decryptedData = RSA.Decrypt(DataToDecrypt, DoOAEPPadding);
            }
            return decryptedData;
        }
        //Catch and display a CryptographicException  
        //to the console.
        catch (CryptographicException e)
        {
            Console.WriteLine(e.ToString());

            return null;
        }

    }
}
Imports System.Security.Cryptography
Imports System.Text

 _

Class RSACSPSample


    Shared Sub Main()
        Try
            'Create a UnicodeEncoder to convert between byte array and string.
            Dim ByteConverter As New UnicodeEncoding()

            'Create byte arrays to hold original, encrypted, and decrypted data.
            Dim dataToEncrypt As Byte() = ByteConverter.GetBytes("Data to Encrypt")
            Dim encryptedData() As Byte
            Dim decryptedData() As Byte

            'Create a new instance of RSACryptoServiceProvider to generate
            'public and private key data.
            Using RSA As New RSACryptoServiceProvider

                'Pass the data to ENCRYPT, the public key information 
                '(using RSACryptoServiceProvider.ExportParameters(false),
                'and a boolean flag specifying no OAEP padding.
                encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(False), False)

                'Pass the data to DECRYPT, the private key information 
                '(using RSACryptoServiceProvider.ExportParameters(true),
                'and a boolean flag specifying no OAEP padding.
                decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(True), False)

                'Display the decrypted plaintext to the console. 
                Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData))
            End Using
        Catch e As ArgumentNullException
            'Catch this exception in case the encryption did
            'not succeed.
            Console.WriteLine("Encryption failed.")
        End Try
    End Sub


    Public Shared Function RSAEncrypt(ByVal DataToEncrypt() As Byte, ByVal RSAKeyInfo As RSAParameters, ByVal DoOAEPPadding As Boolean) As Byte()
        Try
            Dim encryptedData() As Byte
            'Create a new instance of RSACryptoServiceProvider.
            Using RSA As New RSACryptoServiceProvider

                'Import the RSA Key information. This only needs
                'toinclude the public key information.
                RSA.ImportParameters(RSAKeyInfo)

                'Encrypt the passed byte array and specify OAEP padding.  
                'OAEP padding is only available on Microsoft Windows XP or
                'later.  
                encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding)
            End Using
            Return encryptedData
            'Catch and display a CryptographicException  
            'to the console.
        Catch e As CryptographicException
            Console.WriteLine(e.Message)

            Return Nothing
        End Try
    End Function


    Public Shared Function RSADecrypt(ByVal DataToDecrypt() As Byte, ByVal RSAKeyInfo As RSAParameters, ByVal DoOAEPPadding As Boolean) As Byte()
        Try
            Dim decryptedData() As Byte
            'Create a new instance of RSACryptoServiceProvider.
            Using RSA As New RSACryptoServiceProvider
                'Import the RSA Key information. This needs
                'to include the private key information.
                RSA.ImportParameters(RSAKeyInfo)

                'Decrypt the passed byte array and specify OAEP padding.  
                'OAEP padding is only available on Microsoft Windows XP or
                'later.  
                decryptedData = RSA.Decrypt(DataToDecrypt, DoOAEPPadding)
                'Catch and display a CryptographicException  
                'to the console.
            End Using
            Return decryptedData
        Catch e As CryptographicException
            Console.WriteLine(e.ToString())

            Return Nothing
        End Try
    End Function
End Class

下面的代码示例将使用 RSACryptoServiceProvider 创建的密钥信息导出到 RSAParameters 对象中。The following code example exports the key information created using the RSACryptoServiceProvider into an RSAParameters object.

try
{
   //Create a new RSACryptoServiceProvider Object*.
   RSACryptoServiceProvider^ RSA = gcnew 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( false );
}
catch ( CryptographicException^ e ) 
{
   //Catch this exception in case the encryption did
   //not succeed.
   Console::WriteLine( e->Message );
}
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(false);
    }


}
catch (CryptographicException e)
{
    //Catch this exception in case the encryption did
    //not succeed.
    Console.WriteLine(e.Message);

}
Try

    'Create a new RSACryptoServiceProvider object. 
    Dim RSA As 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.
    Dim RSAParams As RSAParameters = RSA.ExportParameters(False)


Catch e As CryptographicException
    'Catch this exception in case the encryption did
    'not succeed.
    Console.WriteLine(e.Message)
End Try

注解

这是 RSA的默认实现。This is the default implementation of RSA.

如果安装了 Microsoft 增强的加密提供程序,则 RSACryptoServiceProvider 支持从384位到16384位的密钥大小。The RSACryptoServiceProvider supports key sizes from 384 bits to 16384 bits in increments of 8 bits if you have the Microsoft Enhanced Cryptographic Provider installed. 如果安装了 Microsoft 基本加密提供程序,则它支持从384位到512位的密钥大小。It supports key sizes from 384 bits to 512 bits in increments of 8 bits if you have the Microsoft Base Cryptographic Provider installed.

有效密钥大小取决于 RSACryptoServiceProvider 实例使用的加密服务提供程序(CSP)。Valid key sizes are dependent on the cryptographic service provider (CSP) that is used by the RSACryptoServiceProvider instance. Windows Csp 在 Windows 8.1Windows 8.1之前为 Windows 版本启用了384到16384位的密钥大小,并为 Windows 8.1Windows 8.1的密钥大小启用了512到16384位。Windows CSPs enable keys sizes of 384 to 16384 bits for Windows versions prior to Windows 8.1Windows 8.1, and key sizes of 512 to 16384 bits for Windows 8.1Windows 8.1. 有关详细信息,请参阅 Windows 文档中的CryptGenKey函数。For more information, see CryptGenKey function in the Windows documentation.

与 Microsoft 加密 API (CAPI)互操作Interoperation with the Microsoft Cryptographic API (CAPI)

与非托管 CAPI 中的 RSA 实现不同,RSACryptoServiceProvider 类会在加密之后和解密之前反转加密的字节数组的顺序。Unlike the RSA implementation in unmanaged CAPI, the RSACryptoServiceProvider class reverses the order of an encrypted array of bytes after encryption and before decryption. 默认情况下,不能通过 CAPI CryptDecrypt 函数对 RSACryptoServiceProvider 类加密的数据进行解密,且无法通过 RSACryptoServiceProvider 类对 CAPI CryptEncrypt 方法加密的数据进行解密。By default, data encrypted by the RSACryptoServiceProvider class cannot be decrypted by the CAPI CryptDecrypt function and data encrypted by the CAPI CryptEncrypt method cannot be decrypted by the RSACryptoServiceProvider class.

如果在 Api 之间进行互操作时不补偿反向排序,RSACryptoServiceProvider 类将引发 CryptographicExceptionIf you do not compensate for the reverse ordering when interoperating between APIs, the RSACryptoServiceProvider class throws a CryptographicException.

若要与 CAPI 进行互操作,必须手动反转加密字节的顺序,然后再将加密数据与另一个 API 进行互操作。To interoperate with CAPI, you must manually reverse the order of encrypted bytes before the encrypted data interoperates with another API. 可以通过调用 Array.Reverse 方法来轻松地反转托管字节数组的顺序。You can easily reverse the order of a managed byte array by calling the Array.Reverse method.

构造函数

RSACryptoServiceProvider()

使用默认密钥初始化 RSACryptoServiceProvider 类的新实例。Initializes a new instance of the RSACryptoServiceProvider class using the default key.

RSACryptoServiceProvider(CspParameters)

使用指定的参数初始化 RSACryptoServiceProvider 类的新实例。Initializes a new instance of the RSACryptoServiceProvider class with the specified parameters.

RSACryptoServiceProvider(Int32)

使用指定的密钥大小初始化 RSACryptoServiceProvider 类的新实例。Initializes a new instance of the RSACryptoServiceProvider class with the specified key size.

RSACryptoServiceProvider(Int32, CspParameters)

使用指定的密钥大小和参数初始化 RSACryptoServiceProvider 类的新实例。Initializes a new instance of the RSACryptoServiceProvider class with the specified key size and parameters.

字段

KeySizeValue

表示非对称算法所用密钥模块的大小(以位为单位)。Represents the size, in bits, of the key modulus used by the asymmetric algorithm.

(继承自 AsymmetricAlgorithm)
LegalKeySizesValue

指定非对称算法支持的密钥大小。Specifies the key sizes that are supported by the asymmetric algorithm.

(继承自 AsymmetricAlgorithm)

属性

CspKeyContainerInfo

获取描述有关加密密钥对的附加信息的 CspKeyContainerInfo 对象。Gets a CspKeyContainerInfo object that describes additional information about a cryptographic key pair.

KeyExchangeAlgorithm

获取可用于 RSA 的此实现的密钥交换算法的名称。Gets the name of the key exchange algorithm available with this implementation of RSA.

KeySize

获取当前密钥的大小。Gets the size of the current key.

LegalKeySizes

获取非对称算法支持的密钥大小。Gets the key sizes that are supported by the asymmetric algorithm.

PersistKeyInCsp

获取或设置一个值,该值指示是否应在加密服务提供程序 (CSP) 中保留此密钥。Gets or sets a value indicating whether the key should be persisted in the cryptographic service provider (CSP).

PublicOnly

获取一个值,该值指示 RSACryptoServiceProvider 对象是否仅包含一个公钥。Gets a value that indicates whether the RSACryptoServiceProvider object contains only a public key.

SignatureAlgorithm

获取可用于 RSA 的此实现的签名算法的名称。Gets the name of the signature algorithm available with this implementation of RSA.

UseMachineKeyStore

获取或设置一个值,该值指示是否应在计算机的密钥存储而不是用户配置文件存储中保留密钥。Gets or sets a value indicating whether the key should be persisted in the computer's key store instead of the user profile store.

方法

Clear()

释放 AsymmetricAlgorithm 类使用的所有资源。Releases all resources used by the AsymmetricAlgorithm class.

(继承自 AsymmetricAlgorithm)
Decrypt(Byte[], Boolean)

使用 RSA 算法对数据进行解密。Decrypts data with the RSA algorithm.

Decrypt(Byte[], RSAEncryptionPadding)

使用指定填充对以前通过 RSA 算法加密的数据进行解密。Decrypts data that was previously encrypted with the RSA algorithm by using the specified padding.

DecryptValue(Byte[])

当前版本不支持此方法。This method is not supported in the current version.

Dispose()

释放 AsymmetricAlgorithm 类的当前实例所使用的所有资源。Releases all resources used by the current instance of the AsymmetricAlgorithm class.

(继承自 AsymmetricAlgorithm)
Dispose(Boolean)

释放 AsymmetricAlgorithm 类使用的非托管资源,并可以选择释放托管资源。Releases the unmanaged resources used by the AsymmetricAlgorithm class and optionally releases the managed resources.

(继承自 AsymmetricAlgorithm)
Encrypt(Byte[], Boolean)

使用 RSA 算法加密数据。Encrypts data with the RSA algorithm.

Encrypt(Byte[], RSAEncryptionPadding)

使用指定的填充,借助 RSA 算法对数据加密。Encrypts data with the RSA algorithm using the specified padding.

EncryptValue(Byte[])

在当前版本中不支持此方法。This method is not supported in the current version.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
ExportCspBlob(Boolean)

导出包含与 RSACryptoServiceProvider 对象关联的密钥信息的 Blob。Exports a blob containing the key information associated with an RSACryptoServiceProvider object.

ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters)

使用基于字节的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式导出当前密钥。Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password.

(继承自 AsymmetricAlgorithm)
ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters)

使用基于字符的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式导出当前密钥。Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.

(继承自 AsymmetricAlgorithm)
ExportParameters(Boolean)

导出 RSAParametersExports the RSAParameters.

ExportPkcs8PrivateKey()

以 PKCS#8 PrivateKeyInfo 格式导出当前密钥。Exports the current key in the PKCS#8 PrivateKeyInfo format.

(继承自 AsymmetricAlgorithm)
ExportRSAPrivateKey()

以 PKCS#1 RSAPrivateKey 格式导出当前密钥。Exports the current key in the PKCS#1 RSAPrivateKey format.

(继承自 RSA)
ExportRSAPublicKey()

以 PKCS#1 RSAPublicKey 格式导出当前密钥的公钥部分。Exports the public-key portion of the current key in the PKCS#1 RSAPublicKey format.

(继承自 RSA)
ExportSubjectPublicKeyInfo()

以 X.509 SubjectPublicKeyInfo 格式导出当前密钥的公钥部分。Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.

(继承自 AsymmetricAlgorithm)
Finalize()
FromXmlString(String)

通过 XML 字符串中的密钥信息初始化 RSA 对象。Initializes an RSA object from the key information from an XML string.

(继承自 RSA)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
HashData(Byte[], Int32, Int32, HashAlgorithmName)

在派生类中被重写时,使用指定的哈希算法计算字节数组指定部分的哈希值。When overridden in a derived class, computes the hash value of a specified portion of a byte array by using a specified hashing algorithm.

(继承自 RSA)
HashData(Stream, HashAlgorithmName)

在派生类中被重写时,使用指定的哈希算法计算指定的二进制流的哈希值。When overridden in a derived class, computes the hash value of a specified binary stream by using a specified hashing algorithm.

(继承自 RSA)
ImportCspBlob(Byte[])

导入表示 RSA 密钥信息的 blob。Imports a blob that represents RSA key information.

ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32)

使用基于字节的密码解密之后,从 PKCS#8 EncryptedPrivateKeyInfo 结构中导入公/私钥对,以替换此对象的密钥。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.

(继承自 RSA)
ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32)

使用基于字符的密码解密之后,从 PKCS#8 EncryptedPrivateKeyInfo 结构中导入公/私钥对,以替换此对象的密钥。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.

(继承自 RSA)
ImportParameters(RSAParameters)

导入指定的 RSAParametersImports the specified RSAParameters.

ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32)

解密后,从 PKCS#8 PrivateKeyInfo 结构中导入公/私钥对,以替换此对象的密钥。Imports the public/private keypair from a PKCS#8 PrivateKeyInfo structure after decryption, replacing the keys for this object.

(继承自 RSA)
ImportRSAPrivateKey(ReadOnlySpan<Byte>, Int32)

解密后,从 PKCS#1 RSAPrivateKey 结构中导入公共/私有密钥对,以便替换此对象的密钥。Imports the public/private keypair from a PKCS#1 RSAPrivateKey structure after decryption, replacing the keys for this object.

(继承自 RSA)
ImportRSAPublicKey(ReadOnlySpan<Byte>, Int32)

解密后,从 PKCS#1 RSAPublicKey 结构中导入公钥,以便替换此对象的密钥。Imports the public key from a PKCS#1 RSAPublicKey structure after decryption, replacing the keys for this object.

(继承自 RSA)
ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32)

解密后,从 X.509 SubjectPublicKeyInfo 结构中导入公钥,以替换此对象的密钥。Imports the public key from an X.509 SubjectPublicKeyInfo structure after decryption, replacing the keys for this object.

(继承自 RSA)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SignData(Byte[], HashAlgorithmName, RSASignaturePadding)

使用指定的哈希算法和填充模式计算指定字节的哈希值,并对生产的哈希值进行签名。Computes the hash value of the specified byte array using the specified hash algorithm and padding mode, and signs the resulting hash value.

(继承自 RSA)
SignData(Byte[], Int32, Int32, HashAlgorithmName, RSASignaturePadding)

使用指定的哈希算法和填充模式计算指定字节数组部分的哈希值并签名生成的哈希值。Computes the hash value of a portion of the specified byte array using the specified hash algorithm and padding mode, and signs the resulting hash value.

(继承自 RSA)
SignData(Byte[], Int32, Int32, Object)

使用指定的哈希算法计算指定字节数组子集的哈希值,并对结果哈希值签名。Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.

SignData(Byte[], Object)

使用指定的哈希算法计算指定字节数组的哈希值,并对计算所得的哈希值签名。Computes the hash value of the specified byte array using the specified hash algorithm, and signs the resulting hash value.

SignData(Stream, HashAlgorithmName, RSASignaturePadding)

使用指定的哈希算法和填充模式计算指定流的哈希值并签名生成的哈希值。Computes the hash value of the specified stream using the specified hash algorithm and padding mode, and signs the resulting hash value.

(继承自 RSA)
SignData(Stream, Object)

使用指定的哈希算法计算指定输入流的哈希值,并对计算所得的哈希值签名。Computes the hash value of the specified input stream using the specified hash algorithm, and signs the resulting hash value.

SignHash(Byte[], HashAlgorithmName, RSASignaturePadding)

计算指定的哈希值的签名,方法是使用指定填充通过私钥进行加密。Computes the signature for the specified hash value by encrypting it with the private key using the specified padding.

SignHash(Byte[], String)

计算指定的哈希值的签名,方法是将其与私钥一起加密。Computes the signature for the specified hash value by encrypting it with the private key.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
ToXmlString(Boolean)

创建并返回包含当前 RSA 对象的密钥的 XML 字符串。Creates and returns an XML string containing the key of the current RSA object.

(继承自 RSA)
TryDecrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) (继承自 RSA)
TryEncrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) (继承自 RSA)
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32)

尝试使用基于字节的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式将当前密钥导出到所提供的缓冲区。Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a byte-based password.

(继承自 RSA)
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32)

尝试使用基于字符的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式将当前密钥导入所提供的缓冲区。Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.

(继承自 RSA)
TryExportPkcs8PrivateKey(Span<Byte>, Int32)

尝试以 PKCS#8 PrivateKeyInfo 格式将当前密钥导出到所提供的缓冲区。Attempts to export the current key in the PKCS#8 PrivateKeyInfo format into a provided buffer.

(继承自 RSA)
TryExportRSAPrivateKey(Span<Byte>, Int32)

尝试以 PKCS#1 RSAPrivateKey 格式将当前密钥导入所提供的缓冲区。Attempts to export the current key in the PKCS#1 RSAPrivateKey format into a provided buffer.

(继承自 RSA)
TryExportRSAPublicKey(Span<Byte>, Int32)

尝试以 PKCS#1 RSAPublicKey 格式将当前密钥导入所提供的缓冲区。Attempts to export the current key in the PKCS#1 RSAPublicKey format into a provided buffer.

(继承自 RSA)
TryExportSubjectPublicKeyInfo(Span<Byte>, Int32)

尝试以 X.509 SubjectPublicKeyInfo 格式将当前密钥导出到所提供的缓冲区。Attempts to export the current key in the X.509 SubjectPublicKeyInfo format into a provided buffer.

(继承自 RSA)
TryHashData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, Int32) (继承自 RSA)
TrySignData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) (继承自 RSA)
TrySignHash(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) (继承自 RSA)
VerifyData(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding)

通过使用指定的哈希算法和填充方式计算指定数据的哈希值,然后将其与提供的签名进行比较来验证数字签名是否有效。Verifies that a digital signature is valid by calculating the hash value of the specified data using the specified hash algorithm and padding, and comparing it to the provided signature.

(继承自 RSA)
VerifyData(Byte[], Int32, Int32, Byte[], HashAlgorithmName, RSASignaturePadding)

通过使用指定的哈希算法和填充模式计算字节数组某部分中数据的哈希值,并将其与所提供的签名进行比较,以此验证数字签名是否有效。Verifies that a digital signature is valid by calculating the hash value of the data in a portion of a byte array using the specified hash algorithm and padding, and comparing it to the provided signature.

(继承自 RSA)
VerifyData(Byte[], Object, Byte[])

通过使用提供的公钥确定签名中的哈希值并将其与所提供数据的哈希值进行比较验证数字签名是否有效。Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the hash value of the provided data.

VerifyData(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) (继承自 RSA)
VerifyData(Stream, Byte[], HashAlgorithmName, RSASignaturePadding)

通过使用指定的哈希算法和填充方式计算指定流的哈希值,然后将其与提供的签名进行比较来验证数字签名是否有效。Verifies that a digital signature is valid by calculating the hash value of the specified stream using the specified hash algorithm and padding, and comparing it to the provided signature.

(继承自 RSA)
VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding)

通过使用指定的哈希算法和填充确定签名中的哈希值,并将其与提供的哈希值进行比较,以此验证数字签名是否有效。Verifies that a digital signature is valid by determining the hash value in the signature using the specified hashing algorithm and padding, and comparing it to the provided hash value.

VerifyHash(Byte[], String, Byte[])

通过使用提供的公钥确定签名中的哈希值并将其与提供的哈希值进行比较来验证数字签名是否有效。Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the provided hash value.

VerifyHash(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) (继承自 RSA)

显式界面实现

IDisposable.Dispose()

有关此成员的说明,请参见 Dispose()For a description of this member, see Dispose().

(继承自 AsymmetricAlgorithm)

适用于

另请参阅