Anonymous avatar Anonymous committed 5972466

Added a simple RSA signing demo.

Comments (0)

Files changed (1)

demo_pk_rsa_sign.py

+"""Demo RSA signing demo for tlslite
+"""
+
+import os
+
+import tlslite
+import tlslite.utils
+from tlslite.utils.Python_RSAKey import Python_RSAKey
+
+
+# Private
+# Load an OpenSSL PEM Key file (not a PEM CERT file), generated with:
+#
+#   openssl genrsa -out key.pem 1024
+#
+fname = os.path.join('test', 'serverX509Key.pem')
+f = open(fname)
+s = f.read()
+f.close()
+y = Python_RSAKey.parsePEM(s)
+
+print 'n', y.n
+print 'e', y.e
+print 'd (private)', y.d
+plain_text = 'hello'
+print 'plain_text', repr(plain_text)
+
+test_signed_hash = y.hashAndSign(plain_text)
+print test_signed_hash
+
+
+n = y.n
+e = y.e
+
+print '-' * 64
+
+## Public
+# n and e is the public key.
+
+x = Python_RSAKey(n=n, e=e)
+
+""" this doesn't work
+f = open("test/serverX509Cert.pem")
+s = f.read()
+f.close()
+x = Python_RSAKey.parsePEM(s)
+"""
+
+
+print 'n', x.n
+print 'e', x.e
+print 'd (private)', x.d
+signed_hash = test_signed_hash
+
+#print x.hashAndSign(plain_text)  # can not hash withOUT the private key
+print x.hashAndVerify(signed_hash, plain_text)
+
+print '-' * 64
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.