System.ImportEncryptionKey(Text, Text) Method

Version: Available or changed with runtime version 1.0.

Points to a password protected file that contains the key on the current server. 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 created or imported if one exists already, as may be the case if upgrading or migrating a system from one set of hardware to another. The IMPORTENCRYPTIONKEY method allows an administrator to specify a file (password protected) which contains a key and imports it to the current Dynamics 365 Business Central service.

Note

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

Syntax

[Ok := ]  System.ImportEncryptionKey(Path: Text, Password: Text)

Note

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

Parameters

Path
 Type: Text
Specifies the file that contains the encryption key.

Password
 Type: Text
Specifies the password the protects the file.

Return Value

[Optional] Ok
 Type: Boolean
true if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

If the import key file cannot be imported, the following error will be displayed: Import Failed. The provided encryption key file contains invalid data and could not be imported.

Example

This code example uses the EncryptionEnabled and EncryptionExists methods to do a check before importing the encryption key.

This example requires that you create a text constant ServerFileName.

if EncryptionEnabled then  
        if EncryptionExists then  
          if not Confirm('Encryption has been enabled and the server already contains an encryption key.\'  
          + 'Importing a key will overwrite any existing key and may result in lost data.\\'  
          + 'Do you wish to continue?') then  
            exit  
       else  
          if not Confirm('Importing a key different from the already configured key will result in data corruption.\\'  
          + 'Do you wish to continue?') then  
            exit  

      if not Upload('Upload encrypted key','','Encrypted Key File (*.ekey)|*.ekey','ExportedKey.ekey',ServerFileName) then  
        Exit;  

      ImportEncryptionKey(ServerFileName,'This is my personal secret');  
      Erase(ServerFileName);  

See Also

System Data Type
Get Started with AL
Developing Extensions