RSAPKCS1SignatureFormatter 类

定义

创建 RSA PKCS #1 1.5 版签名。

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public class RSAPKCS1SignatureFormatter : System.Security.Cryptography.AsymmetricSignatureFormatter
C#
public class RSAPKCS1SignatureFormatter : System.Security.Cryptography.AsymmetricSignatureFormatter
C#
[System.Runtime.InteropServices.ComVisible(true)]
public class RSAPKCS1SignatureFormatter : System.Security.Cryptography.AsymmetricSignatureFormatter
继承
RSAPKCS1SignatureFormatter
属性

示例

以下示例演示如何创建 PKCS #1 版本 1.5 签名。

C#
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);
        }
    }
}

注解

此类用于使用 RSA 算法创建数字签名。

使用 RSAPKCS1SignatureDeformatter 通过 算法验证数字签名 RSA

构造函数

方法

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)

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另请参阅