diff options
author | lloyd <[email protected]> | 2010-06-11 22:41:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-06-11 22:41:27 +0000 |
commit | 781712f324aac1df9b3e7400bb134fb2641974dc (patch) | |
tree | 56ba67d84839a1322c77e0fe91446b7cdf15ae76 /doc | |
parent | e39f418029a82d6f987919bda53334bbe215b61e (diff) |
Demo to_ber in the RSA example/test script
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/python/rsa.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/doc/python/rsa.py b/doc/python/rsa.py index 09ca22314..8ca95ff8b 100755 --- a/doc/python/rsa.py +++ b/doc/python/rsa.py @@ -2,6 +2,18 @@ import botan +def make_into_c_array(ber): + output = 'static unsigned char key_data[%d] = {\n\t' % (len(ber)) + + for (idx,c) in zip(range(len(ber)), ber): + if idx != 0 and idx % 8 == 0: + output += "\n\t" + output += "0x%s, " % (c.encode('hex')) + + output += "\n};\n" + + return output + rng = botan.RandomNumberGenerator() rsa_priv = botan.RSA_PrivateKey(768, rng) @@ -10,9 +22,11 @@ print rsa_priv.to_string() print int(rsa_priv.get_N()) print int(rsa_priv.get_E()) - rsa_pub = botan.RSA_PublicKey(rsa_priv) +print make_into_c_array(rsa_pub.to_ber()) +#print make_into_c_array(rsa_priv.to_ber()) + key = rng.gen_random(20) ciphertext = rsa_pub.encrypt(key, 'EME1(SHA-1)', rng) @@ -23,7 +37,6 @@ plaintext = rsa_priv.decrypt(ciphertext, 'EME1(SHA-1)') print plaintext == key - signature = rsa_priv.sign(key, 'EMSA4(SHA-256)', rng) print rsa_pub.verify(key, signature, 'EMSA4(SHA-256)') |