forked from leifj/rsa_x509_pem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
52 lines (36 loc) · 1.29 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
rsa_x509_pem
Handle OpenSSL PEM RSA keys and x509 certificates in native Python.
© 2011 Andrew D. Yates
https://[email protected]/andrewdyates/rsa_x509_pem.git
https://github.com/andrewdyates
See test.py for unit tests and additional sample usage.
========
SAMPLE USE:
# Read "private_rsa_key.pem", make private RSA key, sign something, verify
>>> with open("private_rsa_key.pem", "rb") as kf: data = kf.read()
... key_dict = parse(data)
... key = get_key(key_dict)
... signature = key.sign(b"Hello.", None)
... assert key.verify(b"Hello.", signature)
# Read "rsa_cert.pem", make public RSA key, verify some signature, print
>>> with open("rsa_cert.pem", "rb") as cf: data = cf.read()
... cert_dict = parse(data)
... key = get_key(cert_dict)
... assert key.verify(b"Hello.", my_signature)
... print cert_dict["subject"]
... print cert_dict["body"]
# Return "nice" public and private key functions from a key object
>>> f_my_public = f_public(key)
... f_my_private = f_private(key)
... msg = b"hello"
... assert msg == f_my_public(f_my_public(msg))
... assert msg == f_my_private(f_my_public(msg))
RUN UNIT TESTS:
$ python test.py
========
Sources:
RSA implementation: PyCrypto
http://www.dlitz.net/software/pycrypto/
PEM implementation: PyASN1
http://pyasn1.sourceforge.net/