root/python/TLSLite/rsa/enc.py

リビジョン 32, 0.7 kB (コミッタ: nakiki, コミット時期: 2 年 前)

--

Line 
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # --nakiki
4
5 import tlslite.X509 as X509
6 import tlslite.utils.keyfactory as keyfactory
7 import array
8
9 def readPEM(fname):
10   f = open (fname, 'r')
11   lines = f.readlines()
12   f.close()
13   return ''.join(lines)
14
15 if __name__ == '__main__':
16   s = readPEM('clientX509Cert.pem')
17   x = X509.X509()
18   cert = x.parse(s)
19
20   # test data
21   data = array.array('B', '\x01\x02\x03\x04' * 5)
22
23   # encryption test
24   encData = cert.publicKey.encrypt(data)
25
26   # decryption test
27   s = readPEM('clientX509Key.pem')
28   privateKey = keyfactory.parsePEMKey(s, True, False)
29   decData = privateKey.decrypt(encData)
30
31   if data == decData:
32     print 'ok'
33   else:
34     print 'ng'
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。