I've created a small piece of Cryptography API, implementing basic functions for Encryption and Hashing.
Require:
[*:zvn4n35m] AHK_L Unicode x32
[*:zvn4n35m] AHK_L Unicode x64
Download:
Crypt.zip
Here is list of current features:
[*:zvn4n35m]Encrypt/Decrypt file
[*:zvn4n35m]Encrypt/Decrypt string using transferable hash
[*:zvn4n35m]Calculating hash of file and any string
[*:zvn4n35m]Supported encryption algorithms - RC4, RC2, 3DES, 3DES_112, AES_128, AES_192, AES_256
[*:zvn4n35m]Supported HASH algorithms - MD5, MD2, SHA1, SHA_256, SHA_384, SHA_512 and HMACI've tried to make all things easy to use as possible.
Here is a list of methods
Crypt.Encrypt.FileEncrypt(pFileIn,pFileOut,password,CryptAlg = 1, HashAlg = 1) Crypt.Encrypt.FileDecrypt(pFileIn,pFileOut,password,CryptAlg = 1, HashAlg = 1) Crypt.Encrypt.StrEncrypt(string,password,CryptAlg = 1, HashAlg = 1) Crypt.Encrypt.StrDecrypt(EncryptedHash,password,CryptAlg = 1, HashAlg = 1) Crypt.Hash.FileHash(pFile,HashAlg = 1,pwd = "",hmac_alg = 1) Crypt.Hash.StrHash(string,HashAlg = 1,pwd = "",hmac_alg = 1) StrDecryptToFile(EncryptedHash,pFileOut,password,CryptAlg = 1, HashAlg = 1) FileEncryptToStr(pFileIn,password,CryptAlg = 1, HashAlg = 1)You can find more info about each parameter inside Crypt.ahk
Example:
#Include Crypt.ahk bytes := Crypt.Encrypt.FileEncrypt("WinError.h","WinError.cr","IwantAcake") ; encrypts file using RC4 encryption and MD5 hash msgbox % "Bytes writen: " bytes bytes := Crypt.Encrypt.FileDecrypt("WinError.cr","WinError2.h","IwantAcake") ; decrypts file encrypted with RC4 and MD5 msgbox % "Bytes writen: " bytes bytes := Crypt.Encrypt.FileEncrypt("WinError.h","WinError.cr","IwantAcake",7,6) ; encrypts file using AES_256 encryption and SHA_512 hash msgbox % "Bytes writen: " bytes bytes := Crypt.Encrypt.FileDecrypt("WinError.cr","WinError2.h","IwantAcake",7,6) ; decrypts file encrypted with AES_256 and SHA_512 msgbox % "Bytes writen: " bytes hash := Crypt.Encrypt.StrEncrypt("MS encryption works in that way","007",5,1) ; encrypts string using AES_128 encryption and MD5 hash msgbox % hash decrypted_string := Crypt.Encrypt.StrDecrypt(hash,"007",5,1) ; decrypts the string using previously generated hash,AES_128 and MD5 msgbox % decrypted_string hash := Crypt.Hash.FileHash("WinError.h") ; get a MD5 HASH of file, its 55EEE971C6357584B4F0EDB6194E2987 msgbox % hash hash := Crypt.Hash.FileHash("WinError.h",3) ; get a SHA1 HASH of file, B65C8825FB47B72A8A15EF85E48C0C8BD5C50D51 msgbox % hash hash := Crypt.Hash.FileHash("WinError.h",6,"Hello,World!",7) ; get a HMAC SHA_512 HASH of file using password "Hello,World!" and AES_256 encryption key msgbox % hash hash := Crypt.Hash.StrHash("RabbidsGoHome",2) ; gets a MD2 HASH of string and result is A81FE29CEA80104F9D6DB0615F805B79 msgbox % hash
Updates:
28.06.2012
Fixed Hash/Encrypting of files with UTF-16 encoding
07.05.2012
StrEncrypt/StrDecrypt uses base64 to encode/decode strings
9.12.2011
Fixed "var" to "static" var definition
Fix for bad password len calculating
21.06.2011:
added following functions:
Crypt.Encrypt.FileEncryptToStr()
Crypt.Encrypt.StrDecryptToFile()
fixed return values - "" instead of 0 in case of errors
few checks added
15.06.2011:
-Added fileds to set string or password encoding
-changed getlasterror() function
-few changes & fixes
06.06.2011:
-Encryption now work correctly with x64 build
-hashable password string changed to unicode from ansi
-no msgbox will appear in case of any errors if script is compiled