TryParsePkcs1Verify Method
TryParsePkcs1Verify(ReadOnlySpan<Byte>, out Int32, out Byte[])
Try to parse the formattedSignature
as a PKCS #1 v1.5 block
for verifying (see RFC 8017).
public static bool TryParsePkcs1Verify(ReadOnlySpan<byte> formattedSignature, out int digestAlgorithm, out byte[] digest)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | formattedSignature | The data to parse. |
System.Int32 | digestAlgorithm | An output argument, the method will set it to one of the values
defined in this class representing the algorithm:
|
System.Byte[] | digest | An output argument, the method will set it to be a new byte array containing the digest portion of the signature. |
Returns
True
if the method is able to parse, false
otherwise.
Remarks
This method will extract the message digest algorithm and the message
digest itself from the formatted signature. If it is successful, it
will return true
. If it cannot extract the information, it
will return false
. The caller will likely decrypt an RSA
signature, then try to parse it as PKCS #1 v1.5. If successful, the
digest is collected. If not, try to parse it as PKCS #1 v2 PSS.
The method will verify that the first byte is 00
, the second
byte is 01
, and that the padding bytes are all FF
. It
will then expect to find 00
and then the DigestInfo.
It will read the DigestInfo to determine the algorithm. If the method
recognizes the OID, it will set the output int digestAlgorithm
to one of the supported values: RsaFormat.Sha1
, Sha256
,
or so on.
Finally, the method will return a byte array containing the actual digest. This will be a new buffer.
This method only supports signatures 128 or 256 bytes (1024 or 2048 bits) long.
If any element fails (the length of the formattedSignature
is
not supported, an expected byte is not there, the OID does not
represent a supported algorithm, the digest is not the proper length,
or so on), the method will return false. If there is an error, the
method might set the output digestAlgorithm
to 0 and the
output digest
to an empty byte array. However, the algorithm
and digest output arguments might contain the purported algorithm and
digest.