PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/gdata/tlslite/utils/PyCrypto_TripleDES.py

http://radioappz.googlecode.com/
Python | 22 lines | 14 code | 7 blank | 1 comment | 1 complexity | f513d97fd83335fe715dbc510754d6fc MD5 | raw file
 1"""PyCrypto 3DES implementation."""
 2
 3from cryptomath import *
 4from TripleDES import *
 5
 6if pycryptoLoaded:
 7    import Crypto.Cipher.DES3
 8
 9    def new(key, mode, IV):
10        return PyCrypto_TripleDES(key, mode, IV)
11
12    class PyCrypto_TripleDES(TripleDES):
13
14        def __init__(self, key, mode, IV):
15            TripleDES.__init__(self, key, mode, IV, "pycrypto")
16            self.context = Crypto.Cipher.DES3.new(key, mode, IV)
17
18        def encrypt(self, plaintext):
19            return self.context.encrypt(plaintext)
20
21        def decrypt(self, ciphertext):
22            return self.context.decrypt(ciphertext)