本文整理汇总了Python中pyDes.des函数的典型用法代码示例。如果您正苦于以下问题:Python des函数的具体用法?Python des怎么用?Python des使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了des函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: digest
def digest (password):
"""This method returns the LM hash of a password in a binary string.
@param password The password to calculate the LM hash.
@return A binary string with the LM value"""
# Get the PASSWORD (uppercase)
upperPass = password.upper()
# Get a list with each character of upperPass in hex format
mPass = map(hex,map(ord,upperPass))
# Pad with NULLs
mPass.extend (['0x00']*(14-len(mPass)))
# Split in 2 7-bytes parts and get the 2 related keys
key1 = __getKey ( ['0x00'] + mPass[:7] )
key2 = __getKey ( ['0x00'] + mPass[7:14] )
# Get the LM hash
BASESTRING = '[email protected]#$%'
des = pyDes.des ( key1, mode=pyDes.ECB, pad='\x00' )
lmhash = des.encrypt( BASESTRING )
des = pyDes.des ( key2, mode=pyDes.ECB, pad='\x00' )
lmhash += des.encrypt( BASESTRING )
# Return the LM hash
return lmhash
示例2: encrypt
def encrypt(text):
if isinstance(text, str) == False:
raise TypeError
key = generateKey()
text = DecryptionIdentifier + text
des = pyDes.des(key, padmode = pyDes.PAD_PKCS5)
return des.encrypt(text)
示例3: decrypt
def decrypt(cipherHex, db_system_id):
cipherText = binascii.unhexlify(cipherHex)
assert cipherText[0] == 5
key = cipherText[1:9]
cipher = pyDes.des(key, mode=pyDes.CBC, IV='\0' * 8, padmode=pyDes.PAD_PKCS5)
plainText = cipher.decrypt(cipherText[9:]).decode('utf-8')
return plainText
示例4: crypt
def crypt(key, data, method):
cipher = pyDes.des(key, padmode=pyDes.PAD_PKCS5)
if method == 'e':
value = cipher.encrypt(data).encode('hex')
if method == 'd':
value = cipher.decrypt(data.decode('hex'))
return value
示例5: get_ep
def get_ep(fileid, sid, token):
src = sid+'_'+fileid+'_'+token
k=pyDes.des('bf09f477', pyDes.ECB, "\0\0\0\0\0\0\0\0", pad='\0', padmode=pyDes.PAD_NORMAL)
print src
d = k.encrypt(str(src))
ep = base64.b64encode(d)
return urllib.quote_plus(ep)
示例6: change_unix_pwd
def change_unix_pwd(self):
"""Change password at unix level after password expiration at website
Level.Uses secret passphrase, old password and new password while
changing password.Returns True on success and False on failure.Also,
logs the error message incase of failure.
"""
old_pwd = self.config['COMMON.OLD_PASSWORD']
new_pwd = self.config['COMMON.PASSWORD']
home = self.config['COMMON.DEFAULT_HOME']
enc_pwd_file = self.config['COMMON.ENC_PASS_FILE']
secret_pphrase = self.config['pass_phrase']
if old_pwd == new_pwd:
self.data['UNIX_MSG'] = "Password change failed : old pwd = new pwd"
return False
try:
key = pyDes.des(secret_pphrase, pad=None, padmode=PAD_PKCS5)
enc_pwd = key.encrypt(new_pwd)
enc_file_loc = home + '/' + enc_pwd_file
fhandle = open(enc_file_loc, "w")
fhandle.write(enc_pwd)
except IOError, err:
logger.error("Password change failed :ERROR: "+str(err))
return False
示例7: encode
def encode(str):
if type(str) == types.UnicodeType:
str = str.encode("utf-8")
key = pyDes.des("12312312", pyDes.CBC, "12312312", pad=None, padmode=pyDes.PAD_PKCS5)
des_data = key.encrypt(str)
b_data = base64.b64encode(des_data)
return b_data
示例8: __desencrypt
def __desencrypt(self, data, key):
""" DES encrypt algorithm, to generate signature. """
ph = '--------'
key = (key + ph)[:8] # 8 digits
des = pyDes.des(key, pyDes.CBC, key, pad=None, padmode=pyDes.PAD_PKCS5)
d = des.encrypt(data)
return binascii.hexlify(d)
示例9: decryptFile
def decryptFile(inputFilePath, outputFilePath):
file = open(inputFilePath)
data = file.read()
k = pyDes.des("DESCRYPT", pyDes.CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=pyDes.PAD_PKCS5)
decrypted_content = k.decrypt(data)
with open(outputFilePath, 'w') as file_handle:
file_handle.write(decrypted_content)
开发者ID:nirajdewani,项目名称:IBM-Bluemix-Object-Storage-based-Storage-as-a-Service.,代码行数:7,代码来源:cloudDrive.py
示例10: tweet
def tweet(request):
import base64
import pyDes
import re
import json
api = create_api(request)
tweet = request.GET["tweet"]
tweetbin = base64.b64decode(tweet)
k = pyDes.des(request.session.session_key[:8], pyDes.ECB)
tweetdec = k.decrypt(tweetbin)
tweetrep = re.compile("\x05*$").sub("", tweetdec)
content_type = "application/json;charset=UTF-8"
try:
api.status_update(tweetrep)
pass
except:
result = {"result": "fail"}
response = django.http.HttpResponseServerError(content=json.dumps(result), content_type=content_type)
else:
result = {"result": "success"}
response = django.http.HttpResponse(content=json.dumps(result), content_type=content_type)
return response
示例11: get_sid_token
def get_sid_token(encrypt_string):
k=pyDes.des('e5571054', pyDes.ECB, "\0\0\0\0\0\0\0\0", pad='\32', padmode=pyDes.PAD_NORMAL)
enh=base64.decodestring(encrypt_string)
data = k.decrypt(enh)
data = data.split('\0')[0]
print data
return data
示例12: read_pm25
def read_pm25():
service = RemotingService(config.AMF_GATEWAY).getService('FlashRemotingServiceLibrary.Sample.getSurvyValue')
extract = lambda s: int(s[8: s.find(u'微克')]) if s[9] != u'—' else None
key = pyDes.des(config.DES_KEY, pyDes.CBC, config.DES_IV)
return map(extract,
[key.decrypt(b64decode(service("PM25", scode))).decode("UTF-8")
for scode in config.STATION.iterkeys()]
) # I'm too lazy...
示例13: acctDecrypt
def acctDecrypt(AcctArray, pwkey):
#decrypt accounts
d = pyDes.des(pwkey)
for acct in AcctArray:
acct[1] = d.decrypt(acct[1],' ')
acct[3] = d.decrypt(acct[3],' ')
acct[4] = d.decrypt(acct[4],' ')
return AcctArray
示例14: CalcMac3DES
def CalcMac3DES(data,initdata,key):
datalen = len(data)
k = pyDes.des(key[:8],pad=None, padmode=pyDes.PAD_NORMAL)
for i in range(datalen/8):
m = ""
for j in range(len(initdata)):
m = m + chr(ord(initdata[j]) ^ ord(data[i*8+j]))
initdata = m
x = k.encrypt(initdata)
initdata = x
k1 = pyDes.des(key[8:],pad=None, padmode=pyDes.PAD_NORMAL)
n = k1.decrypt(initdata)
initdata = k.encrypt(n)
return initdata
示例15: encrypt
def encrypt(self, data):
k = pyDes.des(self.key, pyDes.CBC, self.iv, pad=None, padmode=pyDes.PAD_PKCS5)
d = k.encrypt(data)
print("xxxxoriginxxxxxxxxxx")
print(d)
print('...............................')
print "Encrypt00000000000000000ed:%r" % binascii.hexlify(d)
#d = base64.encodestring(d)
return d