Created
April 20, 2016 02:37
-
-
Save ficapy/2867e346436bcdc372b5ec27170fda24 to your computer and use it in GitHub Desktop.
3DES双倍长加密
This file contains 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
from Crypto.Cipher import DES3 | |
import binascii | |
# 3DES加密32位ASCII字符串得到32位ASCII字符串 | |
# 密匙长度16bytes | |
# 3DES密文长度于明文长度相符,所以要加密得到32位明文中间有16进制转换('1F'→→→'\x1f') | |
# 加密前2个ASCII字符转换成1bytes(限制了只能是0-F) | |
def des3(key, msg): | |
cipher = DES3.new(binascii.unhexlify(key), DES3.MODE_ECB) | |
ret = cipher.encrypt(binascii.unhexlify(msg)) | |
return ''.join(i.upper() for i in binascii.hexlify(ret)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment