This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v18.4
dataStore.provideDataKey( )

dataStore.provideDataKey( ) 


 

dataStore.provideDataKey ( curPassPhrase | curDataKey ) -> Result 
Parameter Type   Description
curPassPhrase | curDataKey  Text, Object in Current passphrase (text) or current data encryption key (object)
Result  Object in Result of the encryption key matching

The dataStore.provideDataKey( ) method allows providing a data encryption key for the current data file of the datastore and detects if the key matches the encrypted data. This command can be used when opening an encrypted database, or when executing any encryption operation that requires the encryption key, such as re-encrypting the data file.

Notes:

  • The dataStore.provideDataKey( ) method must be called in an encrypted database. If it is called in a non-encrypted database, the error 2003 (the encryption key does not match the data.) is returned. Use the Data file encryption status command to determine if the database is encrypted.
  • The dataStore.provideDataKey( ) method cannot be called from a remote 4D or an encrypted remote datastore.

In the parameter, pass the curPassPhrase or curDataKey that matches the database:

  • curPassPhrase: String used to generate the data encryption key. When you use this parameter, an encryption key is generated.
  • curDataKey: Object (with encodedKey property) that contains the data encryption key. This key may have been generated with the New data key command.

If a valid data encryption key is provided, it is added to the keyChain in memory and the encryption mode is enabled:

  • all data modifications in encryptable tables are encrypted on disk (.4DD, .journal. 4Dindx files)
  • all data loaded from encryptable tables is decrypted in memory

 

Result

The result of the command is described in the returned object:

PropertyTypeDescription
successBooleanTrue if the provided encryption key matches the encrypted data, False otherwise
Properties below are returned only if success is FALSE
statusNumberError code (4 if the provided encryption key is wrong)
statusTextTextError message
errorsCollectionStack of errors. The first error has the highest index
[ ].componentSignatureTextInternal component name
[ ].errCodeNumberError number
[ ].messageTextError message

If no curPassphrase or curDataKey is given, dataStore.provideDataKey( ) returns null (no error is generated).

Example  

 C_OBJECT($keyStatus)
 C_TEXT($passphrase)
 
 $passphrase:=Request("Enter the passphrase")
 If(OK=1)
    $keyStatus:=ds.provideDataKey($passphrase)
    If($keyStatus.success)
       ALERT("You have provided a valid encryption key")
    Else
       ALERT("You have provided an invalid encryption key, you will not be able to work with encrypted data")
    End if
 End if



See also 

4D Blog - New 4D commands to work with encrypted data
Data file encryption status
Encrypt data file
New data key

 
PROPERTIES 

Product: 4D
Theme: ORDA - DataStore

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v17 R5

 
ARTICLE USAGE

4D Language Reference ( 4D v18)
4D Language Reference ( 4D v18.4)
4D Language Reference ( 4D v18.6)