本文整理汇总了Python中Crypto.Cipher.DES.MODE_ECB属性的典型用法代码示例。如果您正苦于以下问题:Python DES.MODE_ECB属性的具体用法?Python DES.MODE_ECB怎么用?Python DES.MODE_ECB使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Crypto.Cipher.DES
的用法示例。
在下文中一共展示了DES.MODE_ECB属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decrypt_secret
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def decrypt_secret(secret, key):
"""Python implementation of SystemFunction005.
Decrypts a block of data with DES using given key.
Note that key can be longer than 7 bytes."""
decrypted_data = ''
j = 0 # key index
for i in range(0,len(secret),8):
enc_block = secret[i:i+8]
block_key = key[j:j+7]
des_key = str_to_key(block_key)
des = DES.new(des_key, DES.MODE_ECB)
decrypted_data += des.decrypt(enc_block)
j += 7
if len(key[j:j+7]) < 7:
j = len(key[j:j+7])
(dec_data_len,) = unpack("<L", decrypted_data[:4])
return decrypted_data[8:8+dec_data_len]
示例2: runTest
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def runTest(self):
from Crypto.Cipher import DES
from binascii import b2a_hex
X = []
X[0:] = [b('\x94\x74\xB8\xE8\xC7\x3B\xCA\x7D')]
for i in range(16):
c = DES.new(X[i],DES.MODE_ECB)
if not (i&1): # (num&1) returns 1 for odd numbers
X[i+1:] = [c.encrypt(X[i])] # even
else:
X[i+1:] = [c.decrypt(X[i])] # odd
self.assertEqual(b2a_hex(X[16]),
b2a_hex(b('\x1B\x1A\x2D\xDB\x4C\x64\x24\x38')))
示例3: __decryptSecret
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def __decryptSecret(self, key, value):
# [MS-LSAD] Section 5.1.2
plainText = ''
encryptedSecretSize = unpack('<I', value[:4])[0]
value = value[len(value)-encryptedSecretSize:]
key0 = key
for i in range(0, len(value), 8):
cipherText = value[:8]
tmpStrKey = key0[:7]
tmpKey = self.__cryptoCommon.transformKey(tmpStrKey)
Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
plainText += Crypt1.decrypt(cipherText)
key0 = key0[7:]
value = value[8:]
# AdvanceKey
if len(key0) < 7:
key0 = key[len(key0):]
secret = LSA_SECRET_XP(plainText)
return secret['Secret']
示例4: decryptSecret
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def decryptSecret(key, value):
# [MS-LSAD] Section 5.1.2
plainText = ''
key0 = key
for i in range(0, len(value), 8):
cipherText = value[:8]
tmpStrKey = key0[:7]
tmpKey = transformKey(tmpStrKey)
Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
plainText += Crypt1.decrypt(cipherText)
cipherText = cipherText[8:]
key0 = key0[7:]
value = value[8:]
# AdvanceKey
if len(key0) < 7:
key0 = key[len(key0):]
secret = LSA_SECRET_XP(plainText)
return (secret['Secret'])
示例5: SamDecryptNTLMHash
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def SamDecryptNTLMHash(encryptedHash, key):
# [MS-SAMR] Section 2.2.11.1.1
Block1 = encryptedHash[:8]
Block2 = encryptedHash[8:]
Key1 = key[:7]
Key1 = transformKey(Key1)
Key2 = key[7:14]
Key2 = transformKey(Key2)
Crypt1 = DES.new(Key1, DES.MODE_ECB)
Crypt2 = DES.new(Key2, DES.MODE_ECB)
plain1 = Crypt1.decrypt(Block1)
plain2 = Crypt2.decrypt(Block2)
return plain1 + plain2
示例6: SamEncryptNTLMHash
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def SamEncryptNTLMHash(encryptedHash, key):
# [MS-SAMR] Section 2.2.11.1.1
Block1 = encryptedHash[:8]
Block2 = encryptedHash[8:]
Key1 = key[:7]
Key1 = transformKey(Key1)
Key2 = key[7:14]
Key2 = transformKey(Key2)
Crypt1 = DES.new(Key1, DES.MODE_ECB)
Crypt2 = DES.new(Key2, DES.MODE_ECB)
plain1 = Crypt1.encrypt(Block1)
plain2 = Crypt2.encrypt(Block2)
return plain1 + plain2
示例7: decrypt_secret
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def decrypt_secret(secret, key):
"""Python implementation of SystemFunction005.
Decrypts a block of data with DES using given key.
Note that key can be longer than 7 bytes."""
decrypted_data = ''
j = 0 # key index
for i in range(0, len(secret), 8):
enc_block = secret[i:i + 8]
block_key = key[j:j + 7]
des_key = hashdump.str_to_key(block_key)
des = DES.new(des_key, DES.MODE_ECB)
enc_block = enc_block + "\x00" * int(abs(8 - len(enc_block)) % 8)
decrypted_data += des.decrypt(enc_block)
j += 7
if len(key[j:j + 7]) < 7:
j = len(key[j:j + 7])
(dec_data_len,) = struct.unpack("<L", decrypted_data[:4])
return decrypted_data[8:8 + dec_data_len]
示例8: __decryptHash
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def __decryptHash(self, rid, cryptedHash, constant, newStyle = False):
# Section 2.2.11.1.1 Encrypting an NT or LM Hash Value with a Specified Key
# plus hashedBootKey stuff
Key1,Key2 = self.__cryptoCommon.deriveKey(rid)
Crypt1 = DES.new(Key1, DES.MODE_ECB)
Crypt2 = DES.new(Key2, DES.MODE_ECB)
if newStyle is False:
rc4Key = self.MD5( self.__hashedBootKey[:0x10] + pack("<L",rid) + constant )
rc4 = ARC4.new(rc4Key)
key = rc4.encrypt(cryptedHash['Hash'])
else:
key = self.__cryptoCommon.decryptAES(self.__hashedBootKey[:0x10], cryptedHash['Hash'], cryptedHash['Salt'])[:16]
decryptedHash = Crypt1.decrypt(key[:8]) + Crypt2.decrypt(key[8:])
return decryptedHash
示例9: ChallengeResponse
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def ChallengeResponse(self, Challenge, PasswordHash):
# Generate the NTResponse the client sends the AP
# This is the response part asleap/JtR/hashcat crack
ZPasswordHash = PasswordHash+b'\x00\x00\x00\x00\x00'
des = DES.new(self.__expand_DES_key(ZPasswordHash[0:7]),DES.MODE_ECB)
one = des.encrypt(Challenge)
des = DES.new(self.__expand_DES_key(ZPasswordHash[7:14]),DES.MODE_ECB)
two = des.encrypt(Challenge)
des = DES.new(self.__expand_DES_key(ZPasswordHash[14:21]),DES.MODE_ECB)
tre = des.encrypt(Challenge)
Response = one+two+tre
return Response
示例10: calcKCV
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def calcKCV(keyValue, zAES=False):
"""Calculate KCV for symmetric key.
keyValue - key values as string (DES, 3DES2k, 3DES3k, AES)
zAES - True if key is AES (i.e. encrypt block of '01' instead of '00')
Return 3B-long string."""
if zAES:
assert len(keyValue) in (16, 24, 32), "Wrong length of AES key"
block = '\x01'*16
tkey = AES.new(keyValue, AES.MODE_ECB)
else:
assert len(keyValue) in (8, 16, 24), "Wrong length of (3)DES key"
block = '\x00'*8
if len(keyValue) == 8:
tkey = DES.new(keyValue, DES.MODE_ECB)
else:
tkey = DES3.new(keyValue, DES.MODE_ECB)
return tkey.encrypt(block)[:3]
示例11: decrypt_single_hash
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def decrypt_single_hash(rid, hbootkey, enc_hash, lmntstr):
(des_k1,des_k2) = sid_to_key(rid)
d1 = DES.new(des_k1, DES.MODE_ECB)
d2 = DES.new(des_k2, DES.MODE_ECB)
md5 = MD5.new()
md5.update(hbootkey[:0x10] + pack("<L",rid) + lmntstr)
rc4_key = md5.digest()
rc4 = ARC4.new(rc4_key)
obfkey = rc4.encrypt(enc_hash)
hash = d1.decrypt(obfkey[:8]) + d2.decrypt(obfkey[8:])
return hash
示例12: ds_decrypt_single_hash
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def ds_decrypt_single_hash(rid, enc_hash):
(des_k1,des_k2) = sid_to_key(rid)
d1 = DES.new(des_k1, DES.MODE_ECB)
d2 = DES.new(des_k2, DES.MODE_ECB)
hash = d1.decrypt(enc_hash[:8]) + d2.decrypt(enc_hash[8:])
return hash
示例13: handshake
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def handshake(key, chall):
#https://tools.ietf.org/html/rfc6143#section-7.2.2
#http://www.vidarholen.net/contents/junk/vnc.html
#Truncate to 8 chars
key = key[:8]
# Convert to binary
binary = (' '.join(format(ord(x), 'b') for x in key))
binaryList = binary.split()
count = 0
#Add leading zeros
for x in binaryList:
binaryList[count] = ("0" * (8 - len(binaryList[count]))) + binaryList[count]
count += 1
# Function to mirror the byte
def bitMirror(byte):
return byte[::-1]
flipkey = ""
# turn back into binary
for x in binaryList:
flipkey += struct.pack('B', int(bitMirror(x), 2))
#Pad with NULL bytes
flipkey += "\x00" * (8 - len(flipkey))
#Encryptwith DES
des = DES.new(flipkey, DES.MODE_ECB)
#challenge from server
challenge = chall
# challenge= chall.decode("hex")
response = des.encrypt(challenge)
# return ''.join(x.encode('hex') for x in response)
return response
示例14: decrypt_des_ecb
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def decrypt_des_ecb(key, data, iv=None):
mode = DES.MODE_ECB
if iv:
cipher = DES.new(key, mode, iv)
else:
cipher = DES.new(key, mode)
return cipher.decrypt(data)
示例15: hash_lm
# 需要导入模块: from Crypto.Cipher import DES [as 别名]
# 或者: from Crypto.Cipher.DES import MODE_ECB [as 别名]
def hash_lm(pw):
pw = pw[:14].upper()
pw = pw + ('\0' * (14 - len(pw)))
d1 = DES.new(str_to_key(pw[:7]), DES.MODE_ECB)
d2 = DES.new(str_to_key(pw[7:]), DES.MODE_ECB)
return d1.encrypt(lmkey) + d2.encrypt(lmkey)