You can use the Blowfish external component to integrate encryption into your Omnis Studio applications. Alternatively, you can use the CRYPTO Worker Object to perform encryption and decryption of data using Blowfish, as well as the AES, Camellia, and DES encryption types.
Omnis Studio supports the Blowfish encryption algorithm via a non-visual External Object which you can use in code to provide a layer of security. Blowfish is a fast and freely available encryption algorithm created by Bruce Schneier.
The Blowfish external object contains methods to encrypt and decrypt, as well as initialize the encryption object using an initial key. To create an encryption object, you should create an object variable and specify the Blowfish object as the subtype of the variable. You must initialize the blowfish object with a variable length key using the $initkey() method. For example:
To encrypt binary data use the following method:
Optionally adds a length header if bAddLenHeader is kTrue and then returns the binary encrypted data. The object can use the length header to restore the data length when decrypting the data. The header is 8 bytes.
To decrypt data use the following method:
Decrypts the data and returns the binary result. If bHasLenHeader is kTrue, the object strips the length header and uses it to set the length of the returned data.
You can also use the following methods to encrypt or decrypt Character data:
The $padding property allows you to specify the type of padding to use when encrypting data.
$padding
A kBlowFishPadding... constant that indicates the type of padding to use when encrypting or expect when decrypting (default kBlowFishPaddingNone). A value other than kBlowFishPaddingNone is ignored if you specify a length header.
Valid values of the padding constant are kBlowFishPaddingNone (use or expect no padding) and kBlowFishPaddingPKCS5 (use or expect PKCS5 padding).
The presence of PKCS5 padding allows the code decrypting the data to correctly restore its length, without requiring the non-standard length header. This allows the BlowFish object to be used to encrypt data to be passed to applications other than Omnis – these applications (assuming they have the key) can decrypt the data and set its length correctly.
You can use the encxtea() and decxtea() functions to encrypt and decrypt binary data. The functions are found in the Binary Field group and use the eXtended Tiny Encryption Algorithm (XTEA) to encrypt the data.
encxtea(binary,key)
Returns the binary result of encrypting binary using the eXtended Tiny Encryption Algorithm (XTEA) with the binary key; the key must be 128 bits long.
decxtea(binary,key)
Returns the binary result of decrypting binary (previously encoded using encxtea()) with the binary key; the key must be 128 bits long.
You can encode and decode a string using the encstr() and decstr() functions. You can supply a code or Omnis supplies a default key. The functions are found in the String group of functions.
encstr(string[,key])
Encodes the string using the key. If omitted, Omnis uses its default value for the key. The return value of encstr() is a string that is difficult to decode without knowing the key. To decode the string, and return the original value, use the decstr() function.
decstr(string[,key])
Decodes the string (previously encoded using encstr()) using the key. If omitted, Omnis uses its default value for the key. Note that decstr(encstr(string,key),key) = string.