本文整理汇总了Python中aes.decryptData方法的典型用法代码示例。如果您正苦于以下问题:Python aes.decryptData方法的具体用法?Python aes.decryptData怎么用?Python aes.decryptData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aes
的用法示例。
在下文中一共展示了aes.decryptData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: aes_decrypt
# 需要导入模块: import aes [as 别名]
# 或者: from aes import decryptData [as 别名]
def aes_decrypt(ciphertext, key, iv):
decoded = ciphertext.decode('base64')
password = aes.decryptData(key, iv.encode('utf-8') + decoded)
return unicode(password, 'utf-8')
示例2: decrypt_privkey
# 需要导入模块: import aes [as 别名]
# 或者: from aes import decryptData [as 别名]
def decrypt_privkey(encr_privkey, pw):
bin_pwhash = bin_hash_password(pw)
bin_encr_privkey = encr_privkey.decode('hex')
privkey = aes.decryptData(bin_pwhash, bin_encr_privkey)
return privkey
示例3: computeEncryptionKey
# 需要导入模块: import aes [as 别名]
# 或者: from aes import decryptData [as 别名]
def computeEncryptionKey(password, dictOwnerPass, dictUserPass, dictOE, dictUE, fileID, pElement, dictKeyLength = 128, revision = 3, encryptMetadata = False, passwordType = None):
'''
Compute an encryption key to encrypt/decrypt the PDF file
@param password: The password entered by the user
@param dictOwnerPass: The owner password from the standard security handler dictionary
@param dictUserPass: The user password from the standard security handler dictionary
@param dictOE: The owner encrypted string from the standard security handler dictionary
@param dictUE:The user encrypted string from the standard security handler dictionary
@param fileID: The /ID element in the trailer dictionary of the PDF file
@param pElement: The /P element of the Encryption dictionary
@param dictKeyLength: The length of the key
@param revision: The algorithm revision
@param encryptMetadata: A boolean extracted from the standard security handler dictionary to specify if it's necessary to encrypt the document metadata or not
@param passwordType: It specifies the given password type. It can be 'USER', 'OWNER' or None.
@return: A tuple (status,statusContent), where statusContent is the encryption key in case status = 0 or an error message in case status = -1
'''
if revision != 5:
keyLength = dictKeyLength/8
lenPass = len(password)
if lenPass > 32:
password = password[:32]
elif lenPass < 32:
password += paddingString[:32-lenPass]
md5input = password + dictOwnerPass + struct.pack('<I',abs(int(pElement))) + fileID
if revision > 3 and not encryptMetadata:
md5input += '\xFF'*4
key = hashlib.md5(md5input).digest()
if revision > 2:
counter = 0
while counter < 50:
key = hashlib.md5(key[:keyLength]).digest()
counter += 1
key = key[:keyLength]
elif revision == 2:
key = key[:5]
return (0, key)
else:
if passwordType == 'USER':
password = password.encode('utf-8')[:127]
kSalt = dictUserPass[40:48]
intermediateKey = hashlib.sha256(password + kSalt).digest()
ret = aes.decryptData('\0'*16+dictUE, intermediateKey)
elif passwordType == 'OWNER':
password = password.encode('utf-8')[:127]
kSalt = dictOwnerPass[40:48]
intermediateKey = hashlib.sha256(password + kSalt + dictUserPass).digest()
ret = aes.decryptData('\0'*16+dictOE, intermediateKey)
return ret