[Gambas-user] New gb.crypt.openssl component
Tobias Boege
taboege at ...626...
Mon May 20 23:58:35 CEST 2013
Hi folks,
seems to be the day of new components... I just committed a gb.crypt.openssl
component to wrap the cryptographic functions in OpenSSL's libcrypto. The
idea came actually from Sebastian in conjunction with his gambas-online
project. But maybe it's useful to someone else.
I've been working on it since yesterday. Even if I wrote almost straight
since then, this seemed kind of quick to me - which is usually not a good
sign regarding code quality :-)
Additionally, I'm not even a cryptography novice, so I encourage anyone with
knowledge of this matter to look at the code and report any (security)
problem (but not too much, please).
At least, the test cases (see attachment) work correctly and without crash
or memory leak (on non-Linux platforms, I can't promise anything, though;
there may trigger some assert()s!) and the design seems future-proof.
You basically have two classes which work somewhat alike: Digest and Cipher.
One gets access to an algorithm by giving its name to the array accessors:
Digest["md5"].Hash("some string")
et voila.
The conversion between the string "md5" and the actual hashing function is
done by libcrypto itself. The names are *not* provided by my component. You
can get a full list of all supported algorithm names in the Digest.List:
Dim sName As String
For Each sName In Digest.List.Sort()
Print sName ' May contain duplicates. Don't know why...
Next
It's similar for the Cipher class. It has just Encrypt() and Decrypt() (and
EncryptSalted() and DecryptSalted()) methods instead of Hash().
There's also the HMac class for an HMAC authentication code because this
algorithm has (apparently) no such name to make it findable by the above two
classes.
Regards,
Tobi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_crypt_openssl-0.0.1.tar.gz
Type: application/octet-stream
Size: 5548 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20130520/6f718b72/attachment.obj>
More information about the User
mailing list