Skip to content

Instantly share code, notes, and snippets.

@tlhl28
Created June 16, 2011 06:52
Show Gist options
  • Select an option

  • Save tlhl28/1028800 to your computer and use it in GitHub Desktop.

Select an option

Save tlhl28/1028800 to your computer and use it in GitHub Desktop.
use triple_des(des3) in python;
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import binascii
import hashlib
import base64
import pyDes
# iv and key is hex string
iv = '3132333435363738'
key = '313233343536373839303132333435363738393031323334'
data = "asdf"
iv = binascii.unhexlify(iv)
key = binascii.unhexlify(key)
data = hashlib.sha1(data)
k = pyDes.triple_des(key, pyDes.CBC, iv, pad=None, padmode=pyDes.PAD_PKCS5)
d = k.encrypt(data.digest())
print base64.encodestring(d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment