python 3des模块,使用DES / 3DES与python

what is the best module /package in python to use des /3des for encryption /decryption.

could someone provide example to encrypt data with des/3des on python.

解决方案

pyDes can be used for both, DES and 3DES. Sample usage:

from pyDes import *

data = "Please encrypt my data"

k = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)

d = k.encrypt(data)

print "Encrypted: %r" % d

print "Decrypted: %r" % k.decrypt(d)

assert k.decrypt(d, padmode=PAD_PKCS5) == data

An alternative is the Chillkat Python Encryption Library which supports a lot of encryption algorithms (including DES & 3DES), but it is not free. Sample usage:

crypt.put_CryptAlgorithm("des")

crypt.put_CipherMode("cbc")

crypt.put_KeyLength(64)

crypt.put_PaddingScheme(0)

crypt.put_EncodingMode("hex")

ivHex = "0001020304050607"

crypt.SetEncodedIV(ivHex,"hex")

keyHex = "0001020304050607"

crypt.SetEncodedKey(keyHex,"hex")

encStr = crypt.encryptStringENC("The quick brown fox jumps over the lazy dog.")

print encStr

decStr = crypt.decryptStringENC(encStr)

print decStr

Anyway, I hope that you are aware that neither DES nor 3DES are considered paritcularly safe nowadays, there are many better alternatives (AES in the first place if you want to stick to standards, or Twofish, Blowfish, etc...)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值