Encrypt Example Code

Example Code

Encrypt Function Reference

The following examples show how to encrypt and decrypt files and text.

Text encryption and decryption

Dim iResult As Integer
Dim sEncrypted As String
Dim sDecrypted As String

' Fill sNew to force the string variable to a sufficient size for the returned string (Max 1000)
sEncrypted = Space(1000)

' Encrypt the text
iResult = sEncryptText("Test to encrypt", sEncrypted, "password", 1234567890, True)
If iResult = 0 Then
    MsgBox("Text has been encrypted to '" & sEncrypted & "'")
Else
    MsgBox("Unable to encrypt text")
End If

' Decrypt the text

sDecrypted = Space(1000)
i Result = sDecryptText(sEncrypted, sDecrypted, "password", 1234567890, True)
If iResult = 0 Then
    MsgBox("Text has been decrypted to '" & sDecrypted & "'")
Else
    MsgBox("Unable to decrypt text")
End If

File encryption and decryption

Dim iResult As Integer

' Encrypt a file
iResult = sEncryptFile("\My Documents\plain.txt", "\My Documents\cipher.txt", "password", 1234567890, True)
If iResult = 0 Then
    MsgBox("The file has been encrypted")
Else
    MsgBox("Unable to encrypt file")
End If

' Decrypt a file
iResult = sDecryptFile("\My Documents\cipher.txt", "\My Documents\decrypted.txt", "password", 1234567890, True)
If iResult = 0 Then
    MsgBox("The file has been decrypted")
Else
    MsgBox("Unable to decrypt file")
End If