The simplest way to encrypt a blob is to use the 4D Command--ENCRYPT BLOB. This command requires the use of private and public keypairs. Also, if using Windows, make sure that the 4DSLI.dll is correctly installed on your system. The first step is to generate the keypairs. See GENERATE ENCRYPTION KEYPAIRS for the steps necessary to generate the keys.
Once you have generated the private and public keys, call the command ENCRYPT BLOB. This command requires two parameters and an optional parameter. The first parameter is the blob to be encrypted. The second parameter is the sender's private key used to encrypt the blob. The third parameter is the recipient's public key which is not required unless the sender wants more added security. If the sender passes in the third parameter, then the recipients must have both the public key and the private key in order to decrypt the message. See ENCRYPT BLOB for more information.
Below are example codes to encrypt a blob:
C_BLOB($vbEncrypted;$vbPublicKey)
C_TEXT($vtDecrytped)
C_TIME($vtDocRef)
$vtDocRef:=Open document("encrypted_message.txt")
If (OK=1)
CLOSE DOCUMENT($vtDocRef)
DOCUMENT TO BLOB(Document;$vbEncrypted)
DOCUMENT TO BLOB("PublicKey.txt";$vbPublicKey)
If (OK=1)
DECRYPT BLOB($vbEncrypted;$vbPublicKey)
BLOB TO DOCUMENT("decrypted_message.txt";$vbEncrypted)
End if
End if