FormatPkcs1Sign Method
FormatPkcs1Sign(ReadOnlySpan<Byte>, Int32, Int32)
Build the digest into a PKCS #1 v1.5 formatted block for signing (see RFC 8017).
public static byte[] FormatPkcs1Sign(ReadOnlySpan<byte> digest, int digestAlgorithm, int keySizeBits)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | digest | The message digest value to format. |
System.Int32 | digestAlgorithm | The algorithm used to compute the message digest. It must be one of
the digest algorithms defined in this class: |
System.Int32 | keySizeBits | The size of the key used, in bits. This value must be one of the
|
Returns
A new byte array containing the formatted digest.
Exceptions
Type | Condition |
---|---|
System.ArgumentException | The digest length does not match the |
Remarks
This method will build a new buffer that is keySizeBits
long
and contains the following data.
00 || 01 || FF FF ... FF || 00 || DigestInfo(digest)
The DigestInfo
is the DER encoding of the ASN.1 definition
DigestInfo ::= SEQUENCE {
digestAlgorithm DigestAlgorithm,
digest OCTET STRING
}
This method supports only the following digest algorithms. Note that
the length of the digest
given must match the
digestAlgorithm
, otherwise the method will throw an exception.
SHA-1 RsaFormat.Sha1 20 bytes
SHA-256 RsaFormat.Sha256 32 bytes
SHA-384 RsaFormat.Sha384 48 bytes
SHA-512 RsaFormat.Sha512 64 bytes
This method supports only keySizeBits
values that are defined
in this class as KeySizeBits-x-
, such as
RsaFormat.KeySizeBits1024
(x=1024). You can use one of these
values or simply the actual key size in bits. For example, if the key
size in bits is 1024, then either RsaFormat.KeySizeBits1024
or
1024
are valid input to this method.
For example, if the digest
is 32 bytes long, the
digestAlgorithm
is RsaFormat.Sha256
and the
keySizeBits
is 1024, the result of this method will look like
the following.
00 01 FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF 00 30 31 30
0d 06 09 60 86 48 01 65 03 04 02 01 05 00 04 20
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20