/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. from cryptomath import *
  3. from TripleDES import *
  4. if pycryptoLoaded:
  5. import Crypto.Cipher.DES3
  6. def new(key, mode, IV):
  7. return PyCrypto_TripleDES(key, mode, IV)
  8. class PyCrypto_TripleDES(TripleDES):
  9. def __init__(self, key, mode, IV):
  10. TripleDES.__init__(self, key, mode, IV, "pycrypto")
  11. self.context = Crypto.Cipher.DES3.new(key, mode, IV)
  12. def encrypt(self, plaintext):
  13. return self.context.encrypt(plaintext)
  14. def decrypt(self, ciphertext):
  15. return self.context.decrypt(ciphertext)