Re: Encryption and Python

Ajay Brar <[email protected]>
Newsgroups gmane.comp.python.cryptography
Message-ID <[email protected]>
hi!

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
>>> random=randpool.RandomPool()
>>> RSAkey=RSA.generate(384, random.get_bytes)
>>> hash=MD5.new("testing").digest()
>>> signature=RSAkey.sign(hash,"")
>>> RSAkey.verify(hash, signature)
1
>>>

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
http://www.cs.usyd.edu.au/~abrar1/hons/prototype_0.6/um/verify.py

hope that helps

cheers

On Mon, 10 Jan 2005 10:59:16 +0530, Gagnesh Kumar
<[email protected]> wrote:
> Thanks Ajay.Would you be able to send some working example of
> encryption/decryption.
> 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
> 1
> >>> 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,
> Gagnesh
>
>
> -----Original Message-----
> From: generic crypto class API for Python
> [mailto:[email protected]]On Behalf Of Ajay Brar
> Sent: Saturday, January 08, 2005 5:40 AM
> To: [email protected]
> 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.
>
> cheers
>
> On Fri, 7 Jan 2005 13:56:06 +0100, Gagnesh Kumar
> <[email protected]> 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
> from
> > 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
> http://www.it.usyd.edu.au/~abrar1
> http://ravesandrants.blogspot.com
>


--
--------------
Ajay Brar
http://www.it.usyd.edu.au/~abrar1
http://ravesandrants.blogspot.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.