RSAPKCS1SignatureFormatter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 RSA PKCS #1 1.5 版簽章。
public ref class RSAPKCS1SignatureFormatter : System::Security::Cryptography::AsymmetricSignatureFormatter
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public class RSAPKCS1SignatureFormatter : System.Security.Cryptography.AsymmetricSignatureFormatter
public class RSAPKCS1SignatureFormatter : System.Security.Cryptography.AsymmetricSignatureFormatter
[System.Runtime.InteropServices.ComVisible(true)]
public class RSAPKCS1SignatureFormatter : System.Security.Cryptography.AsymmetricSignatureFormatter
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
type RSAPKCS1SignatureFormatter = class
inherit AsymmetricSignatureFormatter
type RSAPKCS1SignatureFormatter = class
inherit AsymmetricSignatureFormatter
[<System.Runtime.InteropServices.ComVisible(true)>]
type RSAPKCS1SignatureFormatter = class
inherit AsymmetricSignatureFormatter
Public Class RSAPKCS1SignatureFormatter
Inherits AsymmetricSignatureFormatter
- 繼承
- 屬性
範例
下列範例示範如何建立 PKCS #1 1.5 版簽章。
using System;
using System.Security.Cryptography;
class RSASample
{
static void Main()
{
try
{
//Create a new instance of RSA.
using (RSA rsa = RSA.Create())
{
//The hash to sign.
byte[] hash;
using (SHA256 sha256 = SHA256.Create())
{
byte[] data = new byte[] { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };
hash = sha256.ComputeHash(data);
}
//Create an RSASignatureFormatter object and pass it the
//RSA instance to transfer the key information.
RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(rsa);
//Set the hash algorithm to SHA256.
RSAFormatter.SetHashAlgorithm("SHA256");
//Create a signature for HashValue and return it.
byte[] SignedHash = RSAFormatter.CreateSignature(hash);
}
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
}
}
}
Imports System.Security.Cryptography
Friend Class RSASample
Shared Sub Main()
Try
'Create a new instance of RSA.
Using rsa As RSA = RSA.Create()
'The hash to sign.
Dim hash() As Byte
Using sha256 As SHA256 = SHA256.Create()
Dim data() As Byte = { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 }
hash = sha256.ComputeHash(data)
End Using
'Create an RSASignatureFormatter object and pass it the
'RSA to transfer the key information.
Dim RSAFormatter As New RSAPKCS1SignatureFormatter(rsa)
'Set the hash algorithm to SHA256.
RSAFormatter.SetHashAlgorithm("SHA256")
'Create a signature for HashValue and return it.
Dim SignedHash() As Byte = RSAFormatter.CreateSignature(hash)
End Using
Catch e As CryptographicException
Console.WriteLine(e.Message)
End Try
End Sub
End Class
備註
這個類別是用來使用 RSA 演算法建立數字簽名。
使用 RSAPKCS1SignatureDeformatter 來驗證使用演算法的 RSA 數字簽名。
建構函式
RSAPKCS1SignatureFormatter() |
初始化 RSAPKCS1SignatureFormatter 類別的新執行個體。 |
RSAPKCS1SignatureFormatter(AsymmetricAlgorithm) |
使用指定的金鑰,初始化 RSAPKCS1SignatureFormatter 類別的新執行個體。 |
方法
CreateSignature(Byte[]) |
建立所指定資料的 RSA PKCS #1 簽章。 |
CreateSignature(HashAlgorithm) |
建立指定雜湊值的簽章。 (繼承來源 AsymmetricSignatureFormatter) |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
SetHashAlgorithm(String) |
設定建立簽章時所要使用的雜湊演算法。 |
SetKey(AsymmetricAlgorithm) |
設定要用來建立簽章的私密金鑰。 |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |