Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Edge HMI

EncryptData

  • Last UpdatedOct 29, 2026
  • 3 minute read

EncryptData encrypts a string of data using a specified key.

Function

Group

Execution

String Exp.

Windows

Windows Embedded

IoT View

Thin Clients

Mobile Access

EncryptData

String

Synchronous

Yes

Supported (see notes)

Supported (see notes)

Supported

Supported

Executed on Server

Syntax

EncryptData(strData,strKey)

strData

A string (or string tag) to be encrypted, limited to 372 characters. See Notes below for additional information.

strKey

The key to be used to encrypt the data. It can be either a string value up to 16 characters or a numeric value. There are no requirements for the composition of the key, but it should follow the guidelines used to create a strong password. This parameter can be optional if called on a Windows runtime; see Notes below for more details.

Return value

If this function succeeds, it returns the encrypted data as a string value encoded in Base64. See Notes below for additional information.

Notes

After using this function to encrypt the data, you can use the DecryptData function to decrypt it again.

The EncryptData and DecryptData functions use 128-bit AES encryption. Ask a cybersecurity expert whether this type of encryption meets your needs. Do not share your keys with unauthorized personnel, and be careful about where and how you store your keys.

The limit on the size of the strKey string is 128 bits, which is equal to 16 characters at 8 bits per character in the ANSI character set. Using non-Latin characters or symbols (characters not included in the ANSI character set) can complicate the key length calculation because they can have up to 32 bits per character.

After testing, the limit on the strData parameter has been found to be 372 characters. If you try to encrypt a longer string value, this function will fail. The size of the data to be encrypted (the length of the string value passed to the strData parameter) is limited due to a combination of factors. First, the process of encrypting and then encoding data automatically increases the size of the data. Second, different platforms use different methods to encode data as plaintext. And third, this function returns a string value that is limited to 1024 characters (the maximum string value in this software). Therefore, to get a return value that is not more than 1024 characters, the size of the data to be encrypted must be much smaller.

On a Windows runtime (including Windows Embedded) with Windows Data Protection enabled, if this function is called from a Background Task without supplying the second parameter (strKey), the string supplied by strData will be encrypted using the Windows Data Protection key.

If Windows Data Protection is not enabled and strKey is omitted, this function will use a proprietary software encryption key. If using the proprietary encryption key, the length of strEncryptedData is limited to 253 characters. This encryption cannot be decrypted by DecryptData, and is used to encrypt data for specific project uses. For more information, contact customer support.

In any other scenario, this function will fail if strKey is omitted. These scenarios include calling this function on a Windows runtime from anything other than a Background Task, calling this function on a Linux runtime (using either IoT View or Viewer), or calling it from Mobile Access (on Windows or Linux runtime).

Examples

Encrypt a plaintext string using a specified key:

EncryptData("This is a secret.","V4rM#ydar6T^rZn")

Encrypt the value of a tag using a specified key:

EncryptData(MyData,"V4rM#ydar6T^rZn")

Encrypt the value of a tag using a key stored in another tag:

EncryptData(MyData,MyKey)

Encrypt the value of a tag on a Windows runtime with Windows Data Protection enabled or using the proprietary encryption key (called from a Background task only):

EncryptData(MyData)

In This Topic
Related Links