TryParsePkcs1Decrypt Method
TryParsePkcs1Decrypt(ReadOnlySpan<Byte>, out Byte[])
Try to parse the formattedData
as a PKCS #1 v1.5 block that
was the result of decryption (see RFC 8017).
public static bool TryParsePkcs1Decrypt(ReadOnlySpan<byte> formattedData, out byte[] outputData)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | formattedData | The data to parse. |
System.Byte[] | outputData | An output argument, the method will return a new byte array containing the unpadded data portion of the block. |
Returns
True
if the method is able to parse, false
otherwise.
Remarks
This method will extract the data from the formatted data. This is
generally the plaintext (the formatted data is the decrypted block).
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 block, then try to parse it as PKCS #1 v2 OAEP. If
successful, the data is collected. If not, try to parse it as PKCS #1
v1.5. Note that while unlikely, it is possible for an OAEP block to
look like PKCS #1 v1.5. If you don't know which format was used, it is
best to try OAEP first, and if it fails, then try PKCS #1 v1.5.
The method will verify that the first byte is 00
, the second
byte is 02
, and that there are at least 8 padding bytes. It
will then expect to find 00
and then the data to return.
Finally, the method will return a new byte array containing the actual data portion.
Because this method creates a new byte array, and it contains sensitive data, it is a good idea to overwrite the buffer when done with it.
CryptographicOperations.ZeroMemory(outputData);
This method only supports blocks 128 or 256 bytes (1024 or 2048 bits) long.
If any element fails (the length of the formattedData
is
not supported, an expected byte is not there, or so on), the method
will return false
. If there is an error, the method might set
the outputData
argument to an empty array, or it might contain
the purported data. If the return is false
and there is data
in outputData
, that data is meaningless.