Decrypt data BLOB
Decrypt data BLOB ( blobToDecrypt ; keyObject | passPhrase ; salt ; decryptedBLOB ) : Boolean
Parameter | Type | Description | |
---|---|---|---|
blobToDecrypt | Blob | → | BLOB to decrypt |
keyObject | passPhrase | Object, Text | → | JSON object containing the encryption key or passphrase for direct encryption key generation (text) |
salt | Integer | → | Additional salt for algorithm |
decryptedBlob | Blob | ← | decrypted BLOB |
Function result | Boolean | ← | True if decryption has been correctly performed, False otherwise |
Description
The Decrypt data BLOB command decrypts the blobToDecrypt parameter with the same algorithm as 4D uses to decrypt data (AES-256) and returns the result in decryptedBLOB.
You can use either a keyObject or a passPhrase to decrypt the BLOB:
- keyObject: a JSON object containing the encryption key, with the same structure as the object returned by the New data key command
- passPhrase: a string used to generate the encryption key
The number passed in the salt parameter of Decrypt data BLOB must match the one used for encryption.
If the decryption is successful, the decrypted data is returned in the decryptedBLOB parameter and the command returns True.
In case of error, the BLOB is returned empty and the command returns false.
Example
The following example shows how to decrypt an encrypted file located in the RESOURCES folder of the database:
var $fileToDecrypt;$decryptedFile : 4D.File
var $blobToDecrypt;$decryptedBlob : Blob
var $result : Boolean
$fileToDecrypt:=File("/RESOURCES/encryptedConfidential.txt")
$decryptedFile:=File("/RESOURCES/decryptedConfidential.txt")
$blobToDecrypt:=$fileToDecrypt.getContent()
$result:=Decrypt data BLOB($blobToDecrypt;"myPassPhrase";MAXLONG;$decryptedBlob)
$decryptedFile.setContent($decryptedBlob)
The passPhrase and salt used for decryption are identical to the passPhrase and salt used for encryption (see the Encrypt data BLOB example).
See also
Encrypt data BLOB
Encrypt data file
Encrypt your own data with the 4D algorithm
New data key
Properties
Command number | 1774 |
Thread safe | ✓ |