Show / Hide Table of Contents

TryParsePkcs1Verify Method

TryParsePkcs1Verify(ReadOnlySpan<byte>, out int, out byte[])

Try to parse the formattedSignature as a PKCS #1 v1.5 block for verifying (see RFC 8017).

C#
public static bool TryParsePkcs1Verify(ReadOnlySpan<byte> formattedSignature, out int digestAlgorithm, out byte[] digest)

Parameters

Type Name Description
ReadOnlySpan<byte> formattedSignature

The data to parse.

int digestAlgorithm

An output argument, the method will set it to one of the values defined in this class representing the algorithm: RsaFormat.Sha1, and so on.

byte[] digest

An output argument, the method will set it to be a new byte array containing the digest portion of the signature.

Returns

bool

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.

In this article
Back to top Generated by DocFX