Codeunit RSACryptoServiceProvider
Performs asymmetric encryption and decryption using the implementation of the RSA algorithm provided by the cryptographic service provider (CSP).
Properties
Name | Value |
---|---|
Access | Public |
InherentEntitlements | X |
InherentPermissions | X |
Methods
InitializeRSA
Initializes a new instance of RSACryptoServiceProvider with the specified key size and returns the key as an XML string.
procedure InitializeRSA(KeySize: Integer)
Parameters
Name | Type | Description |
---|---|---|
KeySize | Integer |
The size of the key in bits. |
PublicKeyToXmlString
Creates and returns an XML string containing the public key of the current RSA object.
procedure PublicKeyToXmlString(): Text
Returns
Type | Description |
---|---|
Text |
An XML string containing the public key of the current RSA object. |
ToSecretXmlString
Creates and returns an XML string containing the key of the current RSA object.
procedure ToSecretXmlString(IncludePrivateParameters: Boolean): SecretText
Parameters
Name | Type | Description |
---|---|---|
IncludePrivateParameters | Boolean |
true to include a public and private RSA key; false to include only the public key. |
Returns
Type | Description |
---|---|
SecretText |
An XML string containing the key of the current RSA object. |
SignData
Computes the hash value of the specified data and signs it.
procedure SignData(XmlString: SecretText, DataInStream: InStream, HashAlgorithm: Enum "Hash Algorithm", SignatureOutStream: OutStream)
Parameters
Name | Type | Description |
---|---|---|
XmlString | SecretText |
The XML string containing RSA key information. |
DataInStream | InStream |
The input stream to hash and sign. |
HashAlgorithm | System.Security.Encryption."Hash Algorithm" |
The hash algorithm to use to create the hash value. |
SignatureOutStream | OutStream |
The RSA signature stream for the specified data. |
VerifyData
Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the hash value of the provided data.
procedure VerifyData(XmlString: SecretText, DataInStream: InStream, HashAlgorithm: Enum "Hash Algorithm", SignatureInStream: InStream): Boolean
Parameters
Name | Type | Description |
---|---|---|
XmlString | SecretText |
The XML string containing RSA key information. |
DataInStream | InStream |
The input stream of data that was signed. |
HashAlgorithm | System.Security.Encryption."Hash Algorithm" |
The name of the hash algorithm used to create the hash value of the data. |
SignatureInStream | InStream |
The stream of signature data to be verified. |
Returns
Type | Description |
---|---|
Boolean |
True if the signature is valid; otherwise, false. |
Encrypt
Encrypts the specified text with the RSA algorithm.
procedure Encrypt(XmlString: SecretText, PlainTextInStream: InStream, OaepPadding: Boolean, EncryptedTextOutStream: OutStream)
Parameters
Name | Type | Description |
---|---|---|
XmlString | SecretText |
The XML string containing RSA key information. |
PlainTextInStream | InStream |
The input stream to encrypt. |
OaepPadding | Boolean |
True to perform RSA encryption using OAEP padding; otherwise, false to use PKCS#1 padding. |
EncryptedTextOutStream | OutStream |
The RSA encryption stream for the specified text. |
Decrypt
Decrypts the specified text that was previously encrypted with the RSA algorithm.
procedure Decrypt(XmlString: SecretText, EncryptedTextInStream: InStream, OaepPadding: Boolean, DecryptedTextOutStream: OutStream)
Parameters
Name | Type | Description |
---|---|---|
XmlString | SecretText |
The XML string containing RSA key information. |
EncryptedTextInStream | InStream |
The input stream to decrypt. |
OaepPadding | Boolean |
true to perform RSA encryption using OAEP padding; otherwise, false to use PKCS#1 padding. |
DecryptedTextOutStream | OutStream |
The RSA decryption stream for the specified text. |
CreateRSAKeyPair
The CreateRSAKeyPair procedure is a function that generates a public and private RSA key pair.
procedure CreateRSAKeyPair(var PublicKeyInXml: Text, var PrivateKeyInXml: SecretText)
Parameters
Name | Type | Description |
---|---|---|
PublicKeyInXml | Text |
This is an output parameter that returns the public key in XML format. |
PrivateKeyInXml | SecretText |
This is an output parameter that returns the private key in XML format. This is a sensitive information hence marked as SecretText. |