RSACryptoServiceProvider RSACryptoServiceProvider RSACryptoServiceProvider RSACryptoServiceProvider Class

定義

使用由密碼編譯服務供應者 (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
繼承
RSACryptoServiceProviderRSACryptoServiceProviderRSACryptoServiceProviderRSACryptoServiceProvider
屬性
實作

範例

下列程式碼範例會使用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

備註

這是的預設執行RSAThis is the default implementation of RSA.

如果RSACryptoServiceProvider您已安裝 Microsoft 增強型密碼編譯提供者,則支援從384位到16384位的金鑰大小(以8位為增量)。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 Base 密碼編譯提供者,則支援從384位到512位的金鑰大小(以8位的增量)。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位的金鑰大小,並將512的金鑰大小設Windows 8.1Windows 8.1為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. RSACryptoServiceProvider根據預設,capi CryptDecrypt函式無法解密由類別加密的資料,且由 capi CryptEncrypt方法加密的資料無法由RSACryptoServiceProvider類別解密。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類別CryptographicException會擲回。If 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() RSACryptoServiceProvider() RSACryptoServiceProvider()

使用預設的金鑰,初始化 RSACryptoServiceProvider 類別的新執行個體。Initializes a new instance of the RSACryptoServiceProvider class using the default key.

RSACryptoServiceProvider(CspParameters) RSACryptoServiceProvider(CspParameters) RSACryptoServiceProvider(CspParameters) RSACryptoServiceProvider(CspParameters)

使用指定的參數,初始化 RSACryptoServiceProvider 類別的新執行個體。Initializes a new instance of the RSACryptoServiceProvider class with the specified parameters.

RSACryptoServiceProvider(Int32) RSACryptoServiceProvider(Int32) RSACryptoServiceProvider(Int32) RSACryptoServiceProvider(Int32)

使用指定的金鑰大小,初始化 RSACryptoServiceProvider 類別的新執行個體。Initializes a new instance of the RSACryptoServiceProvider class with the specified key size.

RSACryptoServiceProvider(Int32, CspParameters) RSACryptoServiceProvider(Int32, CspParameters) RSACryptoServiceProvider(Int32, CspParameters) RSACryptoServiceProvider(Int32, CspParameters)

使用指定的金鑰大小和參數,初始化 RSACryptoServiceProvider 類別的新執行個體。Initializes a new instance of the RSACryptoServiceProvider class with the specified key size and parameters.

屬性

CspKeyContainerInfo CspKeyContainerInfo CspKeyContainerInfo CspKeyContainerInfo

取得描述密碼編譯金鑰組其他相關資訊的 CspKeyContainerInfo 物件。Gets a CspKeyContainerInfo object that describes additional information about a cryptographic key pair.

KeyExchangeAlgorithm KeyExchangeAlgorithm KeyExchangeAlgorithm KeyExchangeAlgorithm

取得可透過這個 RSA 實作所提供之金鑰交換演算法的名稱。Gets the name of the key exchange algorithm available with this implementation of RSA.

KeySize KeySize KeySize KeySize

取得目前金鑰的大小。Gets the size of the current key.

LegalKeySizes LegalKeySizes LegalKeySizes LegalKeySizes
PersistKeyInCsp PersistKeyInCsp PersistKeyInCsp PersistKeyInCsp

取得或設定值,指出金鑰是否應保存在密碼編譯服務供應者 (CSP) 中。Gets or sets a value indicating whether the key should be persisted in the cryptographic service provider (CSP).

PublicOnly PublicOnly PublicOnly PublicOnly

取得值,指出 RSACryptoServiceProvider 物件是否只包含公開金鑰。Gets a value that indicates whether the RSACryptoServiceProvider object contains only a public key.

SignatureAlgorithm SignatureAlgorithm SignatureAlgorithm SignatureAlgorithm

取得可透過這個 RSA 實作所提供之簽章演算法的名稱。Gets the name of the signature algorithm available with this implementation of RSA.

UseMachineKeyStore UseMachineKeyStore UseMachineKeyStore 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() Clear() Clear() Clear()

釋放 AsymmetricAlgorithm 類別所使用的所有資源。Releases all resources used by the AsymmetricAlgorithm class.

(Inherited from AsymmetricAlgorithm)
Decrypt(Byte[], Boolean) Decrypt(Byte[], Boolean) Decrypt(Byte[], Boolean) Decrypt(Byte[], Boolean)

使用 RSA 演算法解密資料。Decrypts data with the RSA algorithm.

Decrypt(Byte[], RSAEncryptionPadding) Decrypt(Byte[], RSAEncryptionPadding) Decrypt(Byte[], RSAEncryptionPadding) Decrypt(Byte[], RSAEncryptionPadding)

解密先前使用指定填補以 RSA 演算法加密的資料。Decrypts data that was previously encrypted with the RSA algorithm by using the specified padding.

DecryptValue(Byte[]) DecryptValue(Byte[]) DecryptValue(Byte[]) DecryptValue(Byte[])

目前的版本不支援這個方法。This method is not supported in the current version.

Dispose() Dispose() Dispose() Dispose()

釋放 AsymmetricAlgorithm 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the AsymmetricAlgorithm class.

(Inherited from AsymmetricAlgorithm)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 AsymmetricAlgorithm 類別所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the AsymmetricAlgorithm class and optionally releases the managed resources.

(Inherited from AsymmetricAlgorithm)
Encrypt(Byte[], Boolean) Encrypt(Byte[], Boolean) Encrypt(Byte[], Boolean) Encrypt(Byte[], Boolean)

RSA 演算法加密資料。Encrypts data with the RSA algorithm.

Encrypt(Byte[], RSAEncryptionPadding) Encrypt(Byte[], RSAEncryptionPadding) Encrypt(Byte[], RSAEncryptionPadding) Encrypt(Byte[], RSAEncryptionPadding)

使用 RSA 演算法搭配指定的填補來加密資料。Encrypts data with the RSA algorithm using the specified padding.

EncryptValue(Byte[]) EncryptValue(Byte[]) EncryptValue(Byte[]) EncryptValue(Byte[])

目前的版本不支援這個方法。This method is not supported in the current version.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExportCspBlob(Boolean) ExportCspBlob(Boolean) ExportCspBlob(Boolean) ExportCspBlob(Boolean)

匯出 BLOB,其中含有與 RSACryptoServiceProvider 物件相關的金鑰資訊。Exports a blob containing the key information associated with an RSACryptoServiceProvider object.

ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters)

使用位元組型密碼以 PKCS#8 EncryptedPrivateKeyInfo 格式匯出目前金鑰。Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password.

(Inherited from AsymmetricAlgorithm)
ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters)

使用 Char 型密碼以 PKCS#8 EncryptedPrivateKeyInfo 格式匯出目前金鑰。Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.

(Inherited from AsymmetricAlgorithm)
ExportParameters(Boolean) ExportParameters(Boolean) ExportParameters(Boolean) ExportParameters(Boolean)

匯出 RSAParametersExports the RSAParameters.

ExportPkcs8PrivateKey() ExportPkcs8PrivateKey() ExportPkcs8PrivateKey() ExportPkcs8PrivateKey()

以 PKCS#8 PrivateKeyInfo 格式匯出目前金鑰。Exports the current key in the PKCS#8 PrivateKeyInfo format.

(Inherited from AsymmetricAlgorithm)
ExportRSAPrivateKey() ExportRSAPrivateKey() ExportRSAPrivateKey() ExportRSAPrivateKey()

以 PKCS#1 RSAPrivateKey 格式匯出目前金鑰。Exports the current key in the PKCS#1 RSAPrivateKey format.

(Inherited from RSA)
ExportRSAPublicKey() ExportRSAPublicKey() ExportRSAPublicKey() ExportRSAPublicKey()

以 PKCS#1 RSAPublicKey 格式匯出目前金鑰的公開金鑰部分。Exports the public-key portion of the current key in the PKCS#1 RSAPublicKey format.

(Inherited from RSA)
ExportSubjectPublicKeyInfo() ExportSubjectPublicKeyInfo() ExportSubjectPublicKeyInfo() ExportSubjectPublicKeyInfo()

以 X.509 SubjectPublicKeyInfo 格式匯出目前金鑰的公開金鑰部分。Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.

(Inherited from AsymmetricAlgorithm)
Finalize() Finalize() Finalize() Finalize()
FromXmlString(String) FromXmlString(String) FromXmlString(String) FromXmlString(String)

從 XML 字串的金鑰資訊初始化 RSA 物件。Initializes an RSA object from the key information from an XML string.

(Inherited from RSA)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
HashData(Byte[], Int32, Int32, HashAlgorithmName) HashData(Byte[], Int32, Int32, HashAlgorithmName) HashData(Byte[], Int32, Int32, HashAlgorithmName) 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.

(Inherited from RSA)
HashData(Stream, HashAlgorithmName) HashData(Stream, HashAlgorithmName) HashData(Stream, HashAlgorithmName) HashData(Stream, HashAlgorithmName)

在衍生類別中覆寫時,會使用指定的雜湊演算法,來為指定的二進位資料流計算出雜湊值。When overridden in a derived class, computes the hash value of a specified binary stream by using a specified hashing algorithm.

(Inherited from RSA)
ImportCspBlob(Byte[]) ImportCspBlob(Byte[]) ImportCspBlob(Byte[]) ImportCspBlob(Byte[])

匯入代表 RSA 金鑰資訊的 BLOB。Imports a blob that represents RSA key information.

ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32) 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.

(Inherited from RSA)
ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32)

使用 Char 型密碼解密之後,從 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.

(Inherited from RSA)
ImportParameters(RSAParameters) ImportParameters(RSAParameters) ImportParameters(RSAParameters) ImportParameters(RSAParameters)

匯入指定的 RSAParametersImports the specified RSAParameters.

ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32) ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32) ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32) 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.

(Inherited from RSA)
ImportRSAPrivateKey(ReadOnlySpan<Byte>, Int32) ImportRSAPrivateKey(ReadOnlySpan<Byte>, Int32) ImportRSAPrivateKey(ReadOnlySpan<Byte>, Int32) 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.

(Inherited from RSA)
ImportRSAPublicKey(ReadOnlySpan<Byte>, Int32) ImportRSAPublicKey(ReadOnlySpan<Byte>, Int32) ImportRSAPublicKey(ReadOnlySpan<Byte>, Int32) 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.

(Inherited from RSA)
ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32) ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32) ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32) 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.

(Inherited from RSA)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
SignData(Byte[], HashAlgorithmName, RSASignaturePadding) SignData(Byte[], HashAlgorithmName, RSASignaturePadding) SignData(Byte[], HashAlgorithmName, RSASignaturePadding) 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.

(Inherited from RSA)
SignData(Byte[], Int32, Int32, HashAlgorithmName, RSASignaturePadding) SignData(Byte[], Int32, Int32, HashAlgorithmName, RSASignaturePadding) SignData(Byte[], Int32, Int32, HashAlgorithmName, RSASignaturePadding) 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.

(Inherited from RSA)
SignData(Byte[], Int32, Int32, Object) SignData(Byte[], Int32, Int32, Object) SignData(Byte[], Int32, Int32, Object) 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) SignData(Byte[], Object) SignData(Byte[], Object) 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) SignData(Stream, HashAlgorithmName, RSASignaturePadding) SignData(Stream, HashAlgorithmName, RSASignaturePadding) 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.

(Inherited from RSA)
SignData(Stream, Object) SignData(Stream, Object) SignData(Stream, Object) 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) SignHash(Byte[], HashAlgorithmName, RSASignaturePadding) SignHash(Byte[], HashAlgorithmName, RSASignaturePadding) 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) SignHash(Byte[], String) SignHash(Byte[], String) SignHash(Byte[], String)

計算指定雜湊值的簽章,方法是使用私密金鑰將它加密。Computes the signature for the specified hash value by encrypting it with the private key.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
ToXmlString(Boolean) ToXmlString(Boolean) ToXmlString(Boolean) ToXmlString(Boolean)

建立並傳回 XML 字串,其中包含目前 RSA 物件的金鑰。Creates and returns an XML string containing the key of the current RSA object.

(Inherited from RSA)
TryDecrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) TryDecrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) TryDecrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) TryDecrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) Inherited from RSA
TryEncrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) TryEncrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) TryEncrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) TryEncrypt(ReadOnlySpan<Byte>, Span<Byte>, RSAEncryptionPadding, Int32) Inherited from RSA
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32) 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.

(Inherited from RSA)
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32)

使用 Char 型密碼,嘗試以 PKCS#8 EncryptedPrivateKeyInfo 格式將目前的金鑰匯出至提供的緩衝區。Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.

(Inherited from RSA)
TryExportPkcs8PrivateKey(Span<Byte>, Int32) TryExportPkcs8PrivateKey(Span<Byte>, Int32) TryExportPkcs8PrivateKey(Span<Byte>, Int32) TryExportPkcs8PrivateKey(Span<Byte>, Int32)

嘗試以 PKCS#8 PrivateKeyInfo 格式將目前的金鑰匯出至提供的緩衝區。Attempts to export the current key in the PKCS#8 PrivateKeyInfo format into a provided buffer.

(Inherited from RSA)
TryExportRSAPrivateKey(Span<Byte>, Int32) TryExportRSAPrivateKey(Span<Byte>, Int32) TryExportRSAPrivateKey(Span<Byte>, Int32) TryExportRSAPrivateKey(Span<Byte>, Int32)

嘗試以 PKCS#1 RSAPrivateKey 格式將目前金鑰匯出至提供的緩衝區。Attempts to export the current key in the PKCS#1 RSAPrivateKey format into a provided buffer.

(Inherited from RSA)
TryExportRSAPublicKey(Span<Byte>, Int32) TryExportRSAPublicKey(Span<Byte>, Int32) TryExportRSAPublicKey(Span<Byte>, Int32) TryExportRSAPublicKey(Span<Byte>, Int32)

嘗試以 PKCS#1 RSAPublicKey 格式將目前金鑰匯出至提供的緩衝區。Attempts to export the current key in the PKCS#1 RSAPublicKey format into a provided buffer.

(Inherited from RSA)
TryExportSubjectPublicKeyInfo(Span<Byte>, Int32) TryExportSubjectPublicKeyInfo(Span<Byte>, Int32) TryExportSubjectPublicKeyInfo(Span<Byte>, Int32) TryExportSubjectPublicKeyInfo(Span<Byte>, Int32)

嘗試以 X.509 SubjectPublicKeyInfo 格式將目前的金鑰匯出至提供的緩衝區。Attempts to export the current key in the X.509 SubjectPublicKeyInfo format into a provided buffer.

(Inherited from RSA)
TryHashData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, Int32) TryHashData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, Int32) TryHashData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, Int32) TryHashData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, Int32) Inherited from RSA
TrySignData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) TrySignData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) TrySignData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) TrySignData(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) Inherited from RSA
TrySignHash(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) TrySignHash(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) TrySignHash(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) TrySignHash(ReadOnlySpan<Byte>, Span<Byte>, HashAlgorithmName, RSASignaturePadding, Int32) Inherited from RSA
VerifyData(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding) VerifyData(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding) VerifyData(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding) 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.

(Inherited from RSA)
VerifyData(Byte[], Int32, Int32, Byte[], HashAlgorithmName, RSASignaturePadding) VerifyData(Byte[], Int32, Int32, Byte[], HashAlgorithmName, RSASignaturePadding) VerifyData(Byte[], Int32, Int32, Byte[], HashAlgorithmName, RSASignaturePadding) 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.

(Inherited from RSA)
VerifyData(Byte[], Object, Byte[]) VerifyData(Byte[], Object, Byte[]) VerifyData(Byte[], Object, Byte[]) 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) VerifyData(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) VerifyData(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) VerifyData(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) Inherited from RSA
VerifyData(Stream, Byte[], HashAlgorithmName, RSASignaturePadding) VerifyData(Stream, Byte[], HashAlgorithmName, RSASignaturePadding) VerifyData(Stream, Byte[], HashAlgorithmName, RSASignaturePadding) 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.

(Inherited from RSA)
VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding) VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding) VerifyHash(Byte[], Byte[], HashAlgorithmName, RSASignaturePadding) 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[]) VerifyHash(Byte[], String, Byte[]) VerifyHash(Byte[], String, Byte[]) 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) VerifyHash(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) VerifyHash(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) VerifyHash(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, HashAlgorithmName, RSASignaturePadding) Inherited from RSA

欄位

KeySizeValue KeySizeValue KeySizeValue KeySizeValue

表示非對稱演算法使用的金鑰模數大小,以位元為單位。Represents the size, in bits, of the key modulus used by the asymmetric algorithm.

(Inherited from AsymmetricAlgorithm)
LegalKeySizesValue LegalKeySizesValue LegalKeySizesValue LegalKeySizesValue

指定非對稱演算法所支援的金鑰大小。Specifies the key sizes that are supported by the asymmetric algorithm.

(Inherited from AsymmetricAlgorithm)

明確介面實作

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

如需這個成員的說明,請參閱 Dispose()For a description of this member, see Dispose().

(Inherited from AsymmetricAlgorithm)

適用於

另請參閱