Skip to main content
Version: 20 R7 BETA

New data key

New data key ( passPhrase ) : Object

ParameterTypeDescription
passPhraseTextPassphrase to use to generate the AES data encryption key
Function resultObjectObject containing the key (encodedKey property)

Description

The New data key command generates a binary data encryption key from the text passed in the passPhrase parameter.

The encoded key can be saved locally, in order to be stored on an removable device, like an USB key (see Storing data encryption keys in files in the 4D Design Reference). Connecting this device to the machine that hosts the encrypted database will automatically allow the user to access the encrypted data.

You can pass any character in passPhrase. The same passPhrase will always produce the same data encryption key.

Returned value

The returned object contains the following property:

PropertyTypeDescription
encodedKeyTextAES encryption key (SHA 256-bit) generated from the passPhrase

If an empty string was passed in passPhrase, the command returns null.

Example

You want to save an encryption key in a .4DKeyChain file:

 var $dataKey : Object
 var $passphrase : Text
 
 $passphrase:=Request("Enter the passphrase:")
 If(OK=1)
    $dataKey:=New data key($passphrase)
    TEXT TO DOCUMENT("generatedKey.4DKeyChain";JSON Stringify($dataKey))
 End if

See also

4D Blog - New 4D commands to work with encrypted data
Decrypt data BLOB
Discover data key
Encrypt data BLOB
Encrypt data file
Register data key

Properties

Command number1611
Thread safe