Codeunit "Cryptography Management"
Provides helper functions for encryption and hashing. For encryption in an on-premises versions, use it to turn encryption on or off, and import and export the encryption key. Encryption is always turned on for online versions.
Properties
| Name | Value |
|---|---|
| Access | Public |
| InherentEntitlements | X |
| InherentPermissions | X |
Methods
EncryptText
Returns plain text as an encrypted value.
procedure EncryptText(InputString: Text[215]): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text[215] |
The value to encrypt. |
Returns
| Type | Description |
|---|---|
| Text |
Encrypted value. |
Decrypt
Returns encrypted text as plain text.
procedure Decrypt(EncryptedString: Text): Text
Parameters
| Name | Type | Description |
|---|---|---|
| EncryptedString | Text |
The value to decrypt. |
Returns
| Type | Description |
|---|---|
| Text |
Plain text. |
IsEncryptionEnabled
Checks if Encryption is enabled.
procedure IsEncryptionEnabled(): Boolean
Returns
| Type | Description |
|---|---|
| Boolean |
True if encryption is enabled, false otherwise. |
IsEncryptionPossible
Checks whether the encryption key is present, which only works if encryption is enabled.
procedure IsEncryptionPossible(): Boolean
Returns
| Type | Description |
|---|---|
| Boolean |
True if the encryption key exists, false otherwise. |
GetEncryptionIsNotActivatedQst
Gets the recommended question to activate encryption.
procedure GetEncryptionIsNotActivatedQst(): Text
Returns
| Type | Description |
|---|---|
| Text |
String of a recommended question to activate encryption. |
GenerateHash
Generates a hash from a string based on the provided hash algorithm.
procedure GenerateHash(InputString: Text, HashAlgorithmType: Option): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| HashAlgorithmType | Option |
The available hash algorithms include MD5, SHA1, SHA256, SHA384, and SHA512. |
Returns
| Type | Description |
|---|---|
| Text |
Hashed value. |
GenerateHash
Generates a keyed hash from a string based on provided hash algorithm and key.
procedure GenerateHash(InputString: Text, "Key": SecretText, HashAlgorithmType: Option): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| Key | SecretText |
Key to use in the hash algorithm. |
| HashAlgorithmType | Option |
The available hash algorithms include HMACMD5, HMACSHA1, HMACSHA256, HMACSHA384, and HMACSHA512. |
Returns
| Type | Description |
|---|---|
| Text |
Hashed value. |
GenerateHash
Generates a hash from a stream based on the provided hash algorithm.
procedure GenerateHash(InputInStream: InStream, HashAlgorithmType: Option): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputInStream | InStream |
Input string. |
| HashAlgorithmType | Option |
The available hash algorithms include HMACMD5, HMACSHA1, HMACSHA256, HMACSHA384, and HMACSHA512. |
Returns
| Type | Description |
|---|---|
| Text |
Base64 hashed value. |
GenerateHashAsBase64String
Generates a base64 encoded hash from a string based on provided hash algorithm.
procedure GenerateHashAsBase64String(InputString: Text, HashAlgorithmType: Option): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| HashAlgorithmType | Option |
The available hash algorithms include MD5, SHA1, SHA256, SHA384, and SHA512. |
Returns
| Type | Description |
|---|---|
| Text |
Base64 hashed value. |
GenerateHashAsBase64String
Generates a keyed base64 encoded hash from a string based on provided hash algorithm and key.
procedure GenerateHashAsBase64String(InputString: Text, "Key": SecretText, HashAlgorithmType: Option): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| Key | SecretText |
Key to use in the hash algorithm. |
| HashAlgorithmType | Option |
The available hash algorithms include HMACMD5, HMACSHA1, HMACSHA256, HMACSHA384, and HMACSHA512. |
Returns
| Type | Description |
|---|---|
| Text |
Base64 hashed value. |
GenerateBase64KeyedHashAsBase64String
Generates keyed base64 encoded hash from provided string based on provided hash algorithm and base64 key.
procedure GenerateBase64KeyedHashAsBase64String(InputString: Text, "Key": SecretText, HashAlgorithmType: Option): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| Key | SecretText |
Key to use in the hash algorithm. |
| HashAlgorithmType | Option |
The available hash algorithms include HMACMD5, HMACSHA1, HMACSHA256, HMACSHA384, and HMACSHA512. |
Returns
| Type | Description |
|---|---|
| Text |
Base64 hashed value. |
GenerateBase64KeyedHash
Generates keyed base64 encoded hash from provided string based on provided hash algorithm and base64 key.
procedure GenerateBase64KeyedHash(InputString: Text, "Key": SecretText, HashAlgorithmType: Option): Text
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| Key | SecretText |
Key to use in the hash algorithm. |
| HashAlgorithmType | Option |
The available hash algorithms include HMACMD5, HMACSHA1, HMACSHA256, HMACSHA384, and HMACSHA512. |
Returns
| Type | Description |
|---|---|
| Text |
Hashed value. |
SignData
Computes the hash value of the specified string and signs it.
procedure SignData(InputString: Text, XmlString: SecretText, HashAlgorithm: Enum "Hash Algorithm", SignatureOutStream: OutStream)
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string for signing. |
| XmlString | SecretText |
The private key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureOutStream | OutStream |
The stream to write the signature for the specified string. |
SignData
Computes the hash value of the specified data and signs it.
procedure SignData(DataInStream: InStream, XmlString: SecretText, HashAlgorithm: Enum "Hash Algorithm", SignatureOutStream: OutStream)
Parameters
| Name | Type | Description |
|---|---|---|
| DataInStream | InStream |
The stream of input data. |
| XmlString | SecretText |
The private key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureOutStream | OutStream |
The stream to write the signature for the specified input data. |
SignData
Computes the hash value of the specified string and signs it.
procedure SignData(InputString: Text, SignatureKey: Codeunit "Signature Key", HashAlgorithm: Enum "Hash Algorithm", SignatureOutStream: OutStream)
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string for signing. |
| SignatureKey | Codeunit System.Security.Encryption."Signature Key" |
The private key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureOutStream | OutStream |
The stream to write the signature for the specified string. |
SignData
Computes the hash value of the specified data and signs it.
procedure SignData(DataInStream: InStream, SignatureKey: Codeunit "Signature Key", HashAlgorithm: Enum "Hash Algorithm", SignatureOutStream: OutStream)
Parameters
| Name | Type | Description |
|---|---|---|
| DataInStream | InStream |
The stream of input data. |
| SignatureKey | Codeunit System.Security.Encryption."Signature Key" |
The private key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureOutStream | OutStream |
The stream to write the signature for the specified input data. |
SignData
Computes the hash value of the specified string and signs it.
procedure SignData(InputString: Text, XmlString: SecretText, HashAlgorithm: Enum "Hash Algorithm", RSASignaturePadding: Enum "RSA Signature Padding", SignatureOutStream: OutStream)
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string for signing. |
| XmlString | SecretText |
The private key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| RSASignaturePadding | Enum System.Security.Encryption."RSA Signature Padding" |
The padding mode to use for the RSA signature. |
| SignatureOutStream | OutStream |
The stream to write the signature for the specified string. |
VerifyData
Verifies that a digital signature is valid.
procedure VerifyData(InputString: Text, XmlString: Text, HashAlgorithm: Enum "Hash Algorithm", SignatureInStream: InStream): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| XmlString | Text |
The public key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureInStream | InStream |
The stream of signature. |
Returns
| Type | Description |
|---|---|
| Boolean |
True if the signature is valid; otherwise, false. |
VerifyData
Verifies that a digital signature is valid.
procedure VerifyData(DataInStream: InStream, XmlString: Text, HashAlgorithm: Enum "Hash Algorithm", SignatureInStream: InStream): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| DataInStream | InStream |
The stream of input data. |
| XmlString | Text |
The public key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureInStream | InStream |
The stream of signature. |
Returns
| Type | Description |
|---|---|
| Boolean |
True if the signature is valid; otherwise, false. |
VerifyData
Verifies that a digital signature is valid.
procedure VerifyData(InputString: Text, SignatureKey: Codeunit "Signature Key", HashAlgorithm: Enum "Hash Algorithm", SignatureInStream: InStream): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| InputString | Text |
Input string. |
| SignatureKey | Codeunit System.Security.Encryption."Signature Key" |
The private key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureInStream | InStream |
The stream of signature. |
Returns
| Type | Description |
|---|---|
| Boolean |
True if the signature is valid; otherwise, false. |
VerifyData
Verifies that a digital signature is valid.
procedure VerifyData(DataInStream: InStream, SignatureKey: Codeunit "Signature Key", HashAlgorithm: Enum "Hash Algorithm", SignatureInStream: InStream): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
| DataInStream | InStream |
The stream of input data. |
| SignatureKey | Codeunit System.Security.Encryption."Signature Key" |
The private key to use in the hash algorithm. |
| HashAlgorithm | Enum System.Security.Encryption."Hash Algorithm" |
The available hash algorithms are MD5, SHA1, SHA256, SHA384, and SHA512. |
| SignatureInStream | InStream |
The stream of signature. |
Returns
| Type | Description |
|---|---|
| Boolean |
True if the signature is valid; otherwise, false. |