diff options
Diffstat (limited to 'pipermail/pycrypto/2009q3/000119.html')
-rw-r--r-- | pipermail/pycrypto/2009q3/000119.html | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/pipermail/pycrypto/2009q3/000119.html b/pipermail/pycrypto/2009q3/000119.html new file mode 100644 index 0000000..b39a20a --- /dev/null +++ b/pipermail/pycrypto/2009q3/000119.html @@ -0,0 +1,173 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> +<HTML> + <HEAD> + <TITLE> [pycrypto] example + </TITLE> + <LINK REL="Index" HREF="index.html" > + <LINK REL="made" HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20example&In-Reply-To="> + <META NAME="robots" CONTENT="index,nofollow"> + <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> + <LINK REL="Previous" HREF="000118.html"> + <LINK REL="Next" HREF="000120.html"> + </HEAD> + <BODY BGCOLOR="#ffffff"> + <H1>[pycrypto] example</H1> + <B>avo ga</B> + <A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20example&In-Reply-To=" + TITLE="[pycrypto] example">avogatro2007 at googlemail.com + </A><BR> + <I>Mon Aug 24 08:52:26 CST 2009</I> + <P><UL> + <LI>Previous message: <A HREF="000118.html">[pycrypto] ERROR: testRsaUnversionedSignAndVerify failed +</A></li> + <LI>Next message: <A HREF="000120.html">[pycrypto] example +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#119">[ date ]</a> + <a href="thread.html#119">[ thread ]</a> + <a href="subject.html#119">[ subject ]</a> + <a href="author.html#119">[ author ]</a> + </LI> + </UL> + <HR> +<!--beginarticle--> +<PRE>Hi: + +I can't find any example for DSA or ELGAMAL(with google). +so i wrote a simple example. + +<A HREF="http://www.jabbertor.de/wp-content/uploads/2009/08/pycryptotest.txt">http://www.jabbertor.de/wp-content/uploads/2009/08/pycryptotest.txt</A> + +Could someone help to check this? +maybe some Hint about security or perfoumance? +The script is not commented, sry for that + +#!/usr/bin/env python +from Crypto.Cipher import AES +import os,sys,random +#####################AES +print "=====AES 256 Demo=====" +PWD="" +Initial16bytes='0123456789ABCDEF' + +a=0 +for a in xrange(0,32): + b=hex(random.randint(1,16)-1) + PWD+=b.replace("0x","") +print "AES-key",PWD +crypt = AES.new(PWD,AES.MODE_CBC,Initial16bytes) + +plain="blabla what the hack blabla." +restbyte = 32-len(plain)%32 +temp="" +a=0 +for a in xrange(restbyte): + temp+=" " + +plain+=temp +print "text: \n",plain +c= crypt.encrypt(plain) +print "encrypted text: " +print c.encode("hex") +crypt = AES.new(PWD,AES.MODE_CBC,Initial16bytes) +print "decrypted text: \n", crypt.decrypt(c) +#################### RSA +print "\n=====RSA 368 Demo=====" +from Crypto.PublicKey import RSA +from Crypto.Util.randpool import RandomPool +rpool = RandomPool() + +privatekeyCMS = RSA.generate(368, rpool.get_bytes) +privatekeyClient = RSA.generate(368, rpool.get_bytes) +publickeyCMS = privatekeyCMS.publickey() +publickeyClient = privatekeyClient.publickey() + +signed_PWD = privatekeyCMS.sign(PWD,"") +enc_PWD = publickeyClient.encrypt(PWD, "") +print "with publickeyClient encrypted AES-PWD:" +print enc_PWD +print "with privatekeyCMS signed AES-PWD:" +print signed_PWD + + +dec_PWD= privatekeyClient.decrypt(enc_PWD[0]) +print "identity check:\n",publickeyCMS.verify(dec_PWD,signed_PWD) +print "decrypted PWD:\n",dec_PWD + + +#################### ELGAMAL +K="" +a=0 +for a in xrange(0,16): + b=hex(random.randint(1,16)-1) + K+=b.replace("0x","") + + + +print "\n=====ELGamal 368 Demo=====" +from Crypto.PublicKey import ElGamal +from Crypto.Util.randpool import RandomPool +rpool = RandomPool() + +privatekeyCMS = ElGamal.generate(368, rpool.get_bytes) +privatekeyClient = ElGamal.generate(368, rpool.get_bytes) +publickeyCMS = privatekeyCMS.publickey() +publickeyClient = privatekeyClient.publickey() + + +enc_PWD = publickeyClient.encrypt(PWD, K) +print privatekeyCMS.can_sign() +signed_PWD = privatekeyCMS.sign(PWD,97) +print "with publickeyClient encrypted AES-PWD:" +print enc_PWD +print "with privatekeyCMS signed AES-PWD:" +print signed_PWD + + +dec_PWD= privatekeyClient.decrypt(enc_PWD) +print "identity check:\n",publickeyCMS.verify(dec_PWD,signed_PWD) +print "decrypted PWD:\n",dec_PWD + +#################### DSA only sign +K="" +a=0 +for a in xrange(0,16): + b=hex(random.randint(1,16)-1) + K+=b.replace("0x","") + +print "\n=====DSA 368 Demo=====" +from Crypto.PublicKey import DSA +rpool = RandomPool() + +privatekeyCMS = DSA.generate(368, rpool.get_bytes) +publickeyCMS = privatekeyCMS.publickey() +signed_PWD = privatekeyCMS.sign(PWD,K) +print "identity check:\n",publickeyCMS.verify(dec_PWD,signed_PWD) +print "decrypted PWD from ELGAMAL:\n",dec_PWD +-------------- next part -------------- +An HTML attachment was scrubbed... +URL: <A HREF="http://lists.dlitz.net/pipermail/pycrypto/attachments/20090824/e0fe2c33/attachment.htm">http://lists.dlitz.net/pipermail/pycrypto/attachments/20090824/e0fe2c33/attachment.htm</A> +</PRE> + + + +<!--endarticle--> + <HR> + <P><UL> + <!--threads--> + <LI>Previous message: <A HREF="000118.html">[pycrypto] ERROR: testRsaUnversionedSignAndVerify failed +</A></li> + <LI>Next message: <A HREF="000120.html">[pycrypto] example +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#119">[ date ]</a> + <a href="thread.html#119">[ thread ]</a> + <a href="subject.html#119">[ subject ]</a> + <a href="author.html#119">[ author ]</a> + </LI> + </UL> + +<hr> +<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">More information about the pycrypto +mailing list</a><br> +</body></html> |