Encrypt

The Encrypt function allows you to encrypt result data with a user-defined key, using Blowfish with CBC (cipher block chaining). Then, the encrypted data can be sent to a PC or a remote device using an In-Sight function or a native mode command, where the data is decrypted with a decryption application.

Note:
  • The Encrypt function is supported on the In-Sight vision systems running firmware version 5.4.0 or later.
  • The Encrypt function does not have any character limits. However, In-Sight functions that are used to send the encrypted string to a PC or remote device may have the 255 character limits, and return #ERR (please note that the encrypted string will always be longer than the initial result data before encryption). For more information on the character limits, please refer to each In-Sight function's topic.
  • The Cognex In-Sight Encryption sample applications are available for the key generation and decryption.
  • For more information on the encryption/decryption mechanism, please refer to the sample code (C:\Users\Public\Documents\Cognex\In-Sight\In-Sight Sample Projects 5.x.x).

Encrypt Inputs

Syntax: Encrypt(Key (Base64),Value,Output Format)

Parameter Description

Key (Base64)

The key used to encrypt result data (string, Base64 encoded). The recipient will use the same key to decrypt the data.

Note: Use EditPassword to prevent the key from being visible to non-admin users. For more information, see EditPassword.

Value

The result data (string) to encrypt.

Output Format

Select the method to encode the encrypted data.

0 = Base64 (default)

Encodes the encrypted data using Base64.

1 = Hex

Encodes the encrypted data using Hex.

Encrypt Outputs

Results

Returns the encrypted string.

Encrypt Example

In this example, you will encrypt a barcode result decoded by the ReadIDMax function, and then send the encrypted result to a PC using the TCPDevice and WriteDevice functions where the data is decrypted.

  1. Insert a ReadIDMax function, and decode a barcode. The result string is automatically inserted to the spreadsheet. For more information, see ReadIDMax.
  2. Insert an EditPassword function. Enter a key you would like to use to encrypt the result string.

    Note: You can use the Cognex In-Sight Encrypt Generator sample application to generate a key. For more information, refer to the Sample Application section.
  3. Insert an Encrypt function, and configure the property sheet as follows:
    • Key (Base64): Reference the EditPassword cell.
    • Value: Reference the ReadIDMax's result string cell.

      Note: If the result string requires formatting, use FormatString and reference this function. For more information, see Format String Dialog.
    • Output Format: Select the desired encoding method (Base64 or Hex).
  4. The encrypted string is automatically inserted to the spreadsheet. Now you are ready to output the encrypted barcode result to a PC.
  5. Insert a TCPDevice function and use the default values to create a TCP server on port 3000. For more information, see TCPDevice.

    Note: Remove the ReadDevice cell that was automatically added.
  6. Insert a WriteDevice function. For more information, see WriteDevice.
    • Event: Set to A0.
    • Device: Reference the TCPDevice cell (step 5).
    • Data: Reference the Encrypt cell (step 3).
  7. Place the In-Sight vision system Online. Connect with telnet, specifying the Host Name or IP address and port number (for example, C:\ telnet is8402_010203 3000), and then trigger the vision system.

    After each acquisition, the encrypted data will be transmitted.

  8. Decrypt the encrypted string using a decryption application. When decrypting, you need the Key entered in the EditPassword cell (step 2).

    Note: You can use the Cognex In-Sight Encrypt sample application to decrypt the encrypted string. For more information, refer to the Sample Application section below.

Cognex In-Sight Encrypt Sample Applications

The sample applications are located: C:\Users\Public\Documents\Cognex\In-Sight\In-Sight Sample Projects 5.x.x

Key Generation Sample

This sample application generates a key in Base64 format. You can choose to generate a random key, or a key based on a user provided text.

Decryption Sample

This sample application decrypts a message that was encrypted using the In-Sight Encrypt function.