File: hangtest.py

package info (click to toggle)
pyme 0.8.1%2Bclean-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 716 kB
  • ctags: 386
  • sloc: python: 2,512; ansic: 131; makefile: 93
file content (29 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (3)
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
from pyme import core, constants

def Callback(x, y, z):
    """ Callback to give password """
    print "I'm in the callback!"
    return "abcdabcdfs\n"

plaintext = "Hello World!"
crypttext = ""
#First set of data
plaindata1 = core.Data(plaintext)
cryptdata1 = core.Data()

cont = core.Context()
cont.set_armor(True) #ASCII

cont.op_keylist_start("Joe Tester", 1) #use first key
cont.op_encrypt([cont.op_keylist_next()], 1, plaindata1, cryptdata1)
cryptdata1.seek(0,0)
crypttext = cryptdata1.read()
print "Encrypted Data:\n %s" % crypttext

cryptdata2 = core.Data(crypttext)
plaindata2 = core.Data()
cont.set_passphrase_cb(Callback)
cont.op_decrypt(cryptdata2, plaindata2) #freeze here!!!!
plaindata2.seek(0,0)
print "Decrypted Data:\n %s" % plaindata2.read()