System.ExportEncryptionKey(Text) Method

Version: Available or changed with runtime version 1.0.

Returns a password protected temporary filepath containing the encryption key. When encrypting or decrypting data in Dynamics 365 Business Central, an encryption key is used. A single key is used per tenant and every tenant will have a different key. Keys can be exported to a file which may be necessary in the case of upgrading or migrating a system from one set of hardware to another. The EXPORTENCRYPTIONKEY method allows an administrator to specify a destination file for the key and specify a password protection for the file.

Note

This method is supported only in Business Central on-premises.

Syntax

Path :=   System.ExportEncryptionKey(Password: Text)

Note

This method can be invoked without specifying the data type name.

Parameters

Password
 Type: Text
Specifies the password for the encryption key file.

Return Value

Path
 Type: Text
A temporary filepath to where the key is exported.

Remarks

Note

This applies only to on-premises versions of Business Central. For online versions, encryption is always enabled and you cannot turn it off.

If encryption is not enabled or the encryption key is not found, the following error will be displayed: An encryption key is required to complete the request.

Example

This code example uses the ExportEncryptionKey method to return a password protected file that contains an encryption key. With the Download method the file is sent from the Dynamics 365 Business Central service computer to the client computer.

This example requires that you create the following text constants: ExportFileName and ClientFileName.

if not EncryptionEnabled then  
    Error('Encryption has not been enabled.');  
    ExportFileName := ExportEncryptionKey('This is my personal secret');  

    ClientFileName := 'ExportedKey.ekey';  
    Download(ExportFileName,'Save the encrypted key file','','Encrypted Key File (*.ekey)|*.ekey',ClientFileName);  

    Erase(ExportFileName);  

See Also

System Data Type
Get Started with AL
Developing Extensions