diff options
author | lloyd <[email protected]> | 2014-01-01 23:58:46 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-01 23:58:46 +0000 |
commit | 585356e222c5a6116532ba14cce44a2c6cd9c366 (patch) | |
tree | 90a50dec70a8044766fea6a5f9371b7e7c0eb0f3 /src/scripts/examples/rsa.py | |
parent | 48bd53d1918f9ee765313d62eacd054376c0b49e (diff) |
Cull remaining mostly dubious examples. Also remove readme.txt
Diffstat (limited to 'src/scripts/examples/rsa.py')
-rwxr-xr-x | src/scripts/examples/rsa.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/scripts/examples/rsa.py b/src/scripts/examples/rsa.py new file mode 100755 index 000000000..998b72b7b --- /dev/null +++ b/src/scripts/examples/rsa.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + +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(1024, rng) + +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) + +print ciphertext.encode('hex') + +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)') + +# Corrupt the signature, make sure it doesn't verify +signature = signature.replace(signature[0], '0') + +print rsa_pub.verify(key, signature, 'EMSA4(SHA-256)') |