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
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 |
| 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. |
| 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. |