Libraries anvil crypto

namespace crypto
Digest and MAC codes, encryption.

Digest and MAC codes

Anvil crypto library can create message hash codes or checksums from any data. Such codes are useful, for example, in payment applications, where the checksum verifies that data has not been changed. Also the hash codes taken from file contents are useful for checking if the file content is changed or not.

Example. Compute the MD5 digest and hmac and print them out as hex.

 key = "Jefe";
 data = "what do ya want for nothing?";
 digest = crypto.MD5().update(data).final().toHex();
 hmac = crypto.MD5(key).update(data).final().toHex();
 print "The digest is "+digest;
 print "The hmac is "+hmac;
 
This will produce:
 The digest is d03cb659cbf9192dcd066272249f8412
 The hmac is 750c783e6ab0b503eaa86e310a5db738
 

Encryption

Anvil crypto library can also encrypt and decrypt data using DES, TripleDes and Blowfish algorithms.

Example. Encrypt and decrypt a data string using DES.

 key = "Jefe1234";
 data1 = "what do ya want ";
 data2 = "for nothing?";
 cipher = crypto.encrypt(crypto.DES, key);
 crypted = cipher.update(data1);
 crypted = crypted.concat(cipher.update(data2));
 crypted = crypted.concat(cipher.final());
 recovered = crypto.decrypt(crypto.DES, key).final(crypted);
 
Author Jaripekka Salminen

Classes

class Cipher
extends anvil.lang.object
Used for encrypting and decrypting data. Using symmetric algorithms: DES, TripleDES, Blowfish.

class MD5
extends anvil.crypto.MessageHash
This class is used for creating message hash codes: Message Digest or Message Authentication Code (MAC).

class MessageHash
extends anvil.lang.object
This class is used for creating message hash codes: Message Digest or Message Authentication Code (MAC).

class SHA
extends anvil.crypto.MessageHash
This class is used for creating message hash codes: Message Digest or Message Authentication Code (MAC).


Constants

constant BLOWFISH
Blowfish algorithm

constant DES
DES algorithm

constant TRIPLE_DES
3DES algorithm


Functions

string crypt(string password, string salt)
Performs UNIX crypt operation.

Cipher decrypt(string algorithm, object key)
Parameters algorithm -  should be one of supported algoritmhs such as crypto.DES, crypto.TRIPLE_DES, crypto.BLOWFISH.
key -  string or binary key
Returns a cipher object, which takes encrypted data and then returns the original data.

Cipher encrypt(string algorithm, object key)
Parameters algorithm -  should be one of supported algoritmhs such as crypto.DES, crypto.TRIPLE_DES, crypto.BLOWFISH.
key -  string or binary key
Returns a cipher object, which takes data and then returns the encrypted data.