The Security package provides encryption, decryption and hashing functions. The major
functionalities offered in the Security Package are the following:
Some definitions of the modes of the ciphers listed below:
- Electronic codebook (ECB)
- Cipher-block chaining (CBC)
- Propagating cipher-block chaining (PCBC)
- Cipher feedback (CFB)
- Output feedback (OFB)
For more information please see this link at wikipedia.
Examples:
String data = "This is my data"
String key = "TheseAreNotTheDroids"
String enc = Security.Encrypt ( data, key, Security.DES_EDE3_CBC )
String dec = Security.Decrypt ( enc, key, Security.DES_EDE3_CBC )
Bytes benc = Security.EncryptBytes ( data, key, Security.DES_EDE3_CBC )
dec = Security.DecryptBytes ( benc, key, Security.DES_EDE3_CBC )
String hash = Security.Hash ( data, Security.MD5 )
echo ( "MD5 hash = ", hash )
MD5 hash = bf27d031ffc5410071c553be3d93020b
- Encryption/Decryption Types
- RC2 family
-
RC2_ECB
- 128 bit RC2 in ECB mode.
-
RC2_CBC
- 128 bit RC2 in CBC mode.
-
RC2_CFB64
- 128 bit RC2 in CFB mode.
-
RC2_OFB64
- 128 bit RC2 in OFB mode.
-
RC2_40_CBC
- 40 bit RC2 in CBC mode.
-
RC2_64_CBC
- 64 bit RC2 in CBC mode.
- RC4 family
-
RC4
- 128 bit RC4.
-
RC4_40
- 40 bit RC4.
- DES family
-
DES_ECB
- 56 bit DES in ECB mode.
-
DES_CBC
- 56 bit DES in CBC mode.
-
DES_CFB8
- 56 bit DES in 8 bit CFB mode.
-
DES_CFB64
- 56 bit DES in 64 bit CFB mode.
-
DES_OFB64
- 56 bit DES in 64 bit OFB mode.
-
DES_EDE_ECB
- 112 bit 2 key triple DES in ECB mode.
-
DES_EDE_CBC
- 112 bit 2 key triple DES in ECB mode.
-
DES_EDE_CFB64
- 112 bit 2 key triple DES in 64 bit CFB mode.
-
DES_EDE_OFB64
- 112 bit 2 key triple DES in 64 bit OFB mode.
-
DESX_CBC
- 56 bit DESX in CBC mode.
- TripleDES family
-
DES_EDE3_ECB
- 168 bit 3DES in ECB mode.
-
DES_EDE3_CBC
- 168 bit 3DES in CBC mode.
-
DES_EDE3_CFB64
- 168 bit 3DES in 64 bit CFB mode.
-
DES_EDE3_OFB64
- 168 bit 3DES in 64 bit OFB mode.
- Blowfish family
-
BF_ECB
- 128 bit blowfish in ECB mode.
-
BF_CBC
- 128 bit blowfish in CBC mode.
-
BF_CFB64
- 128 bit blowfish in 64 bit CFB mode.
-
BF_OFB64
- 128 bit blowfish in 64 bit OFB mode.
- CAST5 Family
-
CAST5_ECB
- 128 bit CAST5 in ECB mode.
-
CAST5_CBC
- 128 bit CAST5 in CBC mode.
-
CAST5_CFB64
- 128 bit CAST5 in 64 bit CFB mode.
-
CAST5_OFB64
- 128 bit CAST5 in 64 bit OFB mode.
- AES/Rijndael Family
-
AES_128_ECB
- 128 bit AES in ECB mode.
-
AES_128_CBC
- 128 bit AES in CBC mode.
-
AES_128_OFB128
- 128 bit AES in 128 bit OFB mode.
-
AES_128_CFB128
- 128 bit AES in 128 bit CFB mode.
-
AES_192_ECB
- 192 bit AES in ECB mode.
-
AES_192_CBC
- 192 bit AES in CBC mode.
-
AES_192_OFB128
- 192 bit AES in 128 bit OFB mode.
-
AES_192_CFB128
- 192 bit AES in 128 bit CFB mode.
-
AES_256_ECB
- 256 bit AES in ECB mode.
-
AES_256_CBC
- 256 bit AES in CBC mode.
-
AES_256_OFB128
- 256 bit AES in 128 OFB mode.
-
AES_256_CFB128
- 256 bit AES in 128 CFB mode.
-
AES_128_CFB8
- 128 bit AES in 8 bit CFB mode.
-
AES_192_CFB8
- 192 bit AES in 8 bit CFB mode.
-
AES_256_CFB8
- 256 bit AES in 8 bit CFB mode.
- Secure Hash Types
-
MD2
- 128 bit MD2 hash.
-
MD4
- 128 bit MD4 hash.
-
MD5
- 128 bit MD5 hash.
-
SHA
- 160 bit SHA-0 hash.
-
SHA1
- 160 bit SHA-1 hash.
-
SHA224
- 224 bit SHA-2 hash.
-
SHA256
- 256 bit SHA-2 hash.
-
SHA384
- 384 bit SHA-2 hash.
-
SHA512
- 512 bit SHA-2 hash.
-
RIPEMD160
- 160 bit RIPEMD hash.
-
String Encrypt(
String value, String key, Integer encryptionType )
- Encrypts 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ).
Returns a base64 encoded string of bytes
-
String Decrypt(
String value, String key, Integer encryptionType )
- Decrypts 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ).
Value should a base64 encoded string of bytes
-
Bytes EncryptBytes(
String value, String key, Integer encryptionType )
- Encrypts the String 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ). Returns a Bytes object
-
String DecryptBytes(
Bytes value, String key, Integer encryptionType )
- Decrypts the Bytes 'value' with a key generated with 'key' using the encryptionType constant ( see above for constants ). Returns a string.
-
String Hash(
String value, Integer hashType )
- Hashes 'value' with the algorithm specified, returning a hex-encoded string.
Encrypt
String Encrypt(
String value,
String key,
Integer encryptionType,
Encrypt value with key using encryptionType
- Parameters:
-
value |
- |
String containing the value to be encrypted. |
key |
- |
String containing the text used to generate the key to encrypt the value with. |
encryptionType |
- |
Type of encryption to use |
- Returns:
- A base64 encoded string of the encrypted value.
Decrypt
String Decrypt(
String value,
String key,
Integer encryptionType,
Decrypts value with key using encryptionType
- Parameters:
-
value |
- |
String containing the base64 encoded value to be decrypted. |
key |
- |
String containing the text used to generate the key to decrypt the value with. |
encryptionType |
- |
Type of encryption to use |
- Returns:
- A hex encoded string of the decrypted value.
EncryptBytes
Bytes EncryptBytes(
String value,
String key,
Integer encryptionType,
Encrypts value with key using encryptionType
- Parameters:
-
value |
- |
String containing the value to be encrypted. |
key |
- |
String containing the text used to generate the key to encrypt the value with. |
encryptionType |
- |
Type of encryption to use |
- Returns:
- A Bytes object of the encrypted value.
DecryptBytes
String DecryptBytes(
Bytes value,
String key,
Integer encryptionType,
Decrypts value with key using encryptionType
- Parameters:
-
value |
- |
Bytes containing the value to be decrypted. |
key |
- |
String containing the text used to generate the key to decrypt the value with. |
encryptionType |
- |
Type of encryption to use |
- Returns:
- A String object of the decrypted value.
Hash
String Hash(
String value,
Integer hashType,
Hash value using hashType
- Parameters:
-
value |
- |
String containing the value to be decrypted. |
hashType |
- |
Type of hash algorithm to use |
- Returns:
- A hex encoded string of the hash.