[PYTHON-CRYPTO] Encryption and Python
ajay.brar at GMAIL.COM
Mon Jan 10 08:13:38 CET 2005
you need to define your own random function. The toolkit provides a
random function in Crypto.Util
here is an example:
>>> from Crypto.Hash import MD5
>>> from Crypto.PublicKey import RSA
>>> from Crypto.Util import randpool
>>> RSAkey=RSA.generate(384, random.get_bytes)
>>> RSAkey.verify(hash, signature)
you can also define your own random function. i dont know about any
demo directory, the toolkit is quite simple and straightforward and
anyways you can look at the source.
there is some code to verify a signed file at
hope that helps
On Mon, 10 Jan 2005 10:59:16 +0530, Gagnesh Kumar
<Gagnesh.Kumar at india.techspan.com> wrote:
> Thanks Ajay.Would you be able to send some working example of
> The link http://www.amk.ca/python/writing/pycrypt/ does mention demo
> programs but when I installed the stuff from
> http://www.voidspace.org.uk/atlantibots/pythonutils.html#crypto I did not
> get any demo directory as mentioned in the previous link.
> When I tried this program:
> >>> from Crypto.Hash import MD5
> >>> from Crypto.PublicKey import RSA
> >>> RSAkey=RSA.generate(384, randfunc) # This will take a while...
> >>> hash=MD5.new(plaintext).digest()
> >>> signature=RSAkey.sign(hash, "")
> >>> signature # Print what an RSA sig looks like--you don't really care.
> ('\021\317\313\336\264\315' ...,)
> >>> RSAkey.verify(hash, signature) # This sig will check out
> >>> RSAkey.verify(hash[:-1], signature)# This sig will fail
> It failed to find randfunc.Could you please guide me howto compile
> this?Would you be having any working example of encrypting/decrypting data
> using this toolkit?
> Thanks and regards,
> -----Original Message-----
> From: generic crypto class API for Python
> [mailto:PYTHON-CRYPTO at NIC.SURFNET.NL]On Behalf Of Ajay Brar
> Sent: Saturday, January 08, 2005 5:40 AM
> To: PYTHON-CRYPTO at NIC.SURFNET.NL
> Subject: Re: Encryption and Python
> it would help if you could tell us what stuff in the Python
> Cryptography Toolkit doesn't work for you? Perhaps you are not using
> it correctly. I used the toolkit and had no problems whatsoever.
> you could also use OpenSSL with the Python wrapper for it. But if its
> only encrypt/decrypt that you want, Kuchling's toolkit is the best.
> On Fri, 7 Jan 2005 13:56:06 +0100, Gagnesh Kumar
> <gagnesh.kumar at india.techspan.com> wrote:
> > Hi,
> > I would like to encrypt/decrypt my data in Python2.4.
> > What would be the best way to do it.
> > I have been struggling with M2Crypto but there is not much information on
> > the internet about how to install it.The information which I could get
> > the internet has not been of much help either.
> > I installed A.M Kuchling's Python Cryptography Toolkit but some of the
> > stuff mentioned in the manual does not seem to work for me.
> > I am new to Python and Cryptography.
> > Can someone please suggest the sites/links which has working examples of
> > Cryptography for Python?
> > Regards,
> > Gagnesh
> Ajay Brar
More information about the python-crypto