RSA with PyCrypto
Tommy Lindgren
tomyltomyl at linuxlinux.nu
Thu Dec 12 11:15:33 EST 2002
"A.M. Kuchling" <amk at amk.ca> writes:
> On 11 Dec 2002 23:47:47 +0100,
> Tommy Lindgren <tomyltomyl at linuxlinux.nu> wrote:
> You could do that, or A could sign it with their private key.
> Something like:
>
> msg = 'blah blah'
> signed_msg = privkeyA.sign(msg)
> encrypted_msg = pubkeyB.encrypt(msg, '')
... and then B can verify the source with
pubkeyA.verify(decrypted_msg, signed_msg)
?
My revised example:
from Crypto.PublicKey import RSA
from Crypto.Util.randpool import RandomPool
rpool = RandomPool()
privkeyA = RSA.generate(368, rpool.get_bytes)
privkeyB = RSA.generate(368, rpool.get_bytes)
pubkeyA = privkeyA.publickey()
pubkeyB = privkeyB.publickey()
msg = 'blah blah'
signed_msg = privkeyA.sign(msg, '') # Assumed the second parameter
encrypted_msg = pubkeyB.encrypt(msg, '')
decrypted_msg = privkeyB.decrypt(encrypted_msg)
print pubkeyA.verify(decrypted_msg, signed_msg) # Should return true
print pubkeyB.verify(decrypted_msg, signed_msg) # Should return false
The first verify always succeeds and returns '1' (as excepted). The
second sometimes returns '0' (as excepted) and sometimes throws the
exception 'Crypto.PublicKey.RSA.error: Plaintext too large'. Is this
a bug or should I just enclose the call in a try block? Or are the
parameters bad?
--
Tommy Lindgren | o y @ i u . u
41A942131CAA5C | t m l l n x n
^C^C
More information about the Python-list
mailing list