Created
June 16, 2011 06:52
-
-
Save tlhl28/1028800 to your computer and use it in GitHub Desktop.
use triple_des(des3) in python;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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