Encryption (Encrypt/Decrypt)

The Encryption function is used to encrypt or decrypt the contents of a variable.

Syntax

ResultVar = Encryption ( Dest, EncryptSrc, SrcLen, EncryptKey, EncryptInit, EncryptInitLen, EncryptOption)

Remarks

The Encryption function uses the Advanced Encryption Standard (AES) 128 as established by the U.S. National Institute of Standards and Technology. AES uses a symmetric key algorithm; thus, the encryption key used for both encrypting and decrypting the contents of a variable must be the same.

This function returns the number of bytes written to the destination variable. 0 is returned if the function fails or if the destination is not large enough to hold the resulting encrypted or decrypted message.

Two uses of the the Encryption function are:

The initialization process sets up a context (CTX) for the encryption/decryption process. Subsequent calls to encryption/decryption reference this CTX. Thus, only one encryption process at a time can be run by the datalogger.

Parameters

Dest (Destination Variable)

Variable or variable array that holds the output of the encryption or decryption. Note that output to the destination variable can cross array element boundaries. When encrypting, Dest should be declared with a Size greater than the length of EncryptSrc, rounded up to the next multiple of 8 bytes. (For example, if source is 10 bytes, 16 bytes will be placed in destination.)

Type: Variable or Variable Array

EncryptSrc (Encrypt Source)

The variable or variable array that holds the information to be encrypted or decrypted.

Type: Variable or Variable Array

SrcLen (Source Length)

Variable that holds the number of bytes from the source to be encrypted or decrypted. A length of 0 indicates that a length of up to and including the first null character should be used.

Type: Variable declared as Long

EncryptKey (Encryption Key)

Contains the encryption key. The string can be up to 63 bytes in length. If this parameter is null (""), the datalogger's PakBus Encryption Key setting will be used. If neither the EncryptKey parameter nor the PakBus Encryption Key setting contains a value and the Encryption function is in the program, a compile error will be returned.

Type: String Constant

EncryptInit (Encryption Initialization)

A 16-byte value used as the initialization vector for the encryption or decryption process. At the beginning of encryption/decryption, the initialization vector must be initialized. After that, further calls to the encryption/decryption process will use and modify the initialization as part of the encryption/decryption algorithm.

Type: Variable array

EncryptInitLen (Encrypt Initialization Length)

The length of the initialization vector. Valid entry is an integer between 0 and 16. If a non-zero length is used, an ClosedMD5 16 byte checksum of the TCP/IP VTP configuration. checksum of the initialization EncryptInit is calculated and used as the initialization vector for the encryption.

If the process being encrypted is large and requires more than one packet to be transferred, length should be set to 0 after the first packet. This causes the EncryptInit parameter to be ignored and the encryption algorithm uses the initialization vector saved internally.

Type: Integer

EncryptOption (Encrypt Option)

Determines whether EncryptSrc will be encrypted (EncryptOption=0) or decrypted (EncryptOption=1). Right-click to display a pick list of the two options.

NOTE: The FileEncrypt function can be used to encrypt a file stored on the datalogger's file system. FileEncrypt uses a proprietary algorithm and can only be unencrypted by the datalogger. It is typically used to encrypt a program or a portion of a program contained in an Include file that the user would like to hide.