On Thu, Sep 20, 2001 at 11:36:15AM -0400, Peter Osborne wrote:
> We would like to use the ssl libraries to do all this and scip all the file
> stuff & command line utilites but I don't know where to start. Does anyone
> know where I can find some sample code that does simple file
> encryption/decryption using just a file as the key?
Easily done in Python with M2Crypto:
ngps@nova:/tmp$ cat 1.py
#!/usr/bin/env python
from M2Crypto import EVP
from cStringIO import StringIO
def cipher_filter(cipher, inf, outf):
while 1:
buf = inf.read()
if not buf:
break
outf.write(cipher.update(buf))
outf.write(cipher.final())
return outf
# Encrypt
inf = open('/tmp/test.txt')
outf = StringIO()
cipher = EVP.Cipher('des_ede3_cbc', 'pass phrase', 'init_vector', 1)
outf = cipher_filter(cipher, inf, outf)
ctxt = outf.getvalue()
print `ctxt`
# Decrypt
inf = StringIO(ctxt)
outf = StringIO()
cipher = EVP.Cipher('des_ede3_cbc', 'pass phrase', 'init_vector', 0)
outf = cipher_filter(cipher, inf, outf)
ptxt = outf.getvalue()
print ptxt
ngps@nova:/tmp$ cat /tmp/test.txt
the quick brown fox
ngps@nova:/tmp$ ./1.py
'\xf5\xeb\xb9\xeeS[zy\xa6\x88"\xe9j\xe6j^@!\x18\xdcq\xa3\xa9\xc8'
the quick brown fox
<plug>
Python is an interpreted OO programming language that combines remarkable
power with very clear syntax. It has modules, classes, exceptions, very
high-level dynamic data types and dynamic typing.
More info on Python here:
http://www.python.org/
M2Crypto is a Python interface to OpenSSL. Apart from ciphers and hashes,
it also does SSL, HTTPS, FTP/TLS, S/MIME, etc. M2Crypto works on both Un*x
and Windows.
Get it here:
http://www.post1.com/home/ngps/m2/
</plug>
Hope this helps.
--
Ng Pheng Siong <[EMAIL PROTECTED]> * http://www.post1.com/home/ngps
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]