Files
pcp/bindings/py/test.py

31 lines
740 B
Python
Raw Normal View History

2014-12-14 14:38:30 +01:00
#!/usr/local/bin/python
from pypcp import *
2014-12-14 18:06:45 +01:00
from pprint import pprint
2014-12-14 14:38:30 +01:00
2014-12-22 19:48:36 +01:00
# import secret key
zbobsec = open("../../tests/key-bobby-sec", "r").read()
bobsec = Key(encoded=zbobsec, passphrase="b")
#bobsec.dump()
2014-12-14 18:06:45 +01:00
2014-12-22 19:48:36 +01:00
# import public key
zalipub = open("../../tests/key-alicia-pub", "r").read()
alipub = PublicKey(encoded=zalipub)
#alipub.dump()
2014-12-14 18:06:45 +01:00
2014-12-22 19:48:36 +01:00
# always required
ctx = Context()
2014-12-22 19:48:36 +01:00
# symmetric encryption (self mode)
sencrypted = ctx.encrypt(string="hello world", passphrase="x", armor=True)
print sencrypted
2014-12-22 19:48:36 +01:00
# asymmetric encryption bob => alice
ctx.addkey(bobsec)
ctx.recipients(alipub)
2014-12-22 19:48:36 +01:00
aencrypted = ctx.encrypt(string="hello world", armor=True, sign=False)
#print aencrypted
2014-12-14 18:06:45 +01:00
2014-12-22 19:48:36 +01:00
sclear = ctx.decrypt(string=sencrypted, passphrase="x")
print sclear