This library offers basic cryptographic facilities for Lua: a hash (digest) function, an a pair crypt/decrypt. (download)
md5 (message)
Computes the MD5 message-digest. This function takes as input a message of arbitrary length and content and returns as output a 128-bit "fingerprint" (or "message digest") of the input. (The output is formated as a binary string with 16 characters.) It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. (see RFC 1321)
crypt (message, key [,seed])
Encrypts a string, using MD5 in CFB (Cipher-feedback mode).
message
is an arbitrary binary string to be encrypted.
key
is an arbitrary binary string to be used as a key.
seed
is an arbitrary binary string to be used as a seed;
Returns the cyphertext (as a binary string).
If no seed is provided,
the function uses the result of time()
as a seed.
It is recommended that you use different seeds for each message;
the seed itself is not private, and should contain no private data,
because it goes plain in the beginning of the encrypted message.
The length of the cyphertext is the length of the message plus the length of the seed plus one.
decrypt (message, key)
Decrypts a string.
The input message
must be the result of a previous call
to crypt
.
For any msg
, key
,
and seed
, we have that
decrypt(crypt(msg, key, seed), key) == msg
exor (s1, s2)
Does a bit-a-bit exclusive or of strings s1
and s2
.
Both strings must have the same length,
which will be also the length of the resulting string.
md5.h
void md5lib_open (lua_State *L);
Register the above Lua functions in the given state.
void md5 (const char *message, long len, char *output);
Computes the MD5 message-digest of message
.
len
is the length of message
.
output
is a buffer that receives the result;
it must have at least HASHSIZE
bytes (128 bits).
$Id: md5.html,v 1.2 2000/11/09 19:24:14 roberto Exp $