Python Crypto.Cipher.DES.MODE_ECB Examples
The following are 30
code examples of Crypto.Cipher.DES.MODE_ECB().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Crypto.Cipher.DES
, or try the search function
.
Example #1
Source File: encryptionencoding.py From chepy with GNU General Public License v3.0 | 12 votes |
def triple_des_encrypt( self, key: str, iv: str = "0000000000000000", mode: str = "CBC", hex_key: bool = False, hex_iv: bool = True, ): """Encrypt raw state with Triple DES Triple DES applies DES three times to each block to increase key size. Key: Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br>You can generate a password-based key using one of the KDF operations. IV: The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes. Padding: In CBC and ECB mode, PKCS#7 padding will be used. Args: key (str): Required. The secret key iv (str, optional): IV for certain modes only. Defaults to '0000000000000000'. mode (str, optional): Encryption mode. Defaults to 'CBC'. hex_key (bool, optional): If the secret key is a hex string. Defaults to False. hex_iv (bool, optional): If the IV is a hex string. Defaults to True. Returns: Chepy: The Chepy object. Examples: >>> Chepy("some data").triple_des_encrypt("super secret password !!", mode="ECB").o b"f8b27a0d8c837edc8fb00ea85f502fb4" """ self.__check_mode(mode) key, iv = self._convert_key(key, iv, hex_key, hex_iv) if mode == "CBC": cipher = DES3.new(key, mode=DES3.MODE_CBC, iv=iv) self.state = cipher.encrypt(pad(self._convert_to_bytes(), 8)) return self elif mode == "ECB": cipher = DES3.new(key, mode=DES3.MODE_ECB) self.state = cipher.encrypt(pad(self._convert_to_bytes(), 8)) return self elif mode == "CTR": cipher = DES3.new(key, mode=DES3.MODE_CTR, nonce=b"") self.state = cipher.encrypt(self._convert_to_bytes()) return self elif mode == "OFB": cipher = DES3.new(key, mode=DES3.MODE_OFB, iv=iv) self.state = cipher.encrypt(self._convert_to_bytes()) return self
Example #2
Source File: crypto.py From cracke-dit with MIT License | 6 votes |
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
Example #3
Source File: test_DES.py From earthengine with MIT License | 6 votes |
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')))
Example #4
Source File: crypto.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
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
Example #5
Source File: encryptionencoding.py From chepy with GNU General Public License v3.0 | 6 votes |
def des_encrypt( self, key: str, iv: str = "0000000000000000", mode: str = "CBC", hex_key: bool = False, hex_iv: bool = True, ): """Encrypt raw state with DES DES is a previously dominant algorithm for encryption, and was published as an official U.S. Federal Information Processing Standard (FIPS). It is now considered to be insecure due to its small key size. DES uses a key length of 8 bytes (64 bits).<br>Triple DES uses a key length of 24 bytes. You can generate a password-based key using one of the KDF operations. The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes. Padding: In CBC and ECB mode, PKCS#7 padding will be used. Args: key (str): Required. The secret key iv (str, optional): IV for certain modes only. Defaults to '0000000000000000'. mode (str, optional): Encryption mode. Defaults to 'CBC'. hex_key (bool, optional): If the secret key is a hex string. Defaults to False. hex_iv (bool, optional): If the IV is a hex string. Defaults to True. Returns: Chepy: The Chepy object. Examples: >>> Chepy("some data").des_encrypt("70617373776f7264", hex_key=True).o b"1ee5cb52954b211d1acd6e79c598baac" To encrypt using a differnt mode >>> Chepy("some data").des_encrypt("password", mode="CTR").o b"0b7399049b0267d93d" """ self.__check_mode(mode) key, iv = self._convert_key(key, iv, hex_key, hex_iv) if mode == "CBC": cipher = DES.new(key, mode=DES.MODE_CBC, iv=iv) self.state = cipher.encrypt(pad(self._convert_to_bytes(), 8)) return self elif mode == "ECB": cipher = DES.new(key, mode=DES.MODE_ECB) self.state = cipher.encrypt(pad(self._convert_to_bytes(), 8)) return self elif mode == "CTR": cipher = DES.new(key, mode=DES.MODE_CTR, nonce=b"") self.state = cipher.encrypt(self._convert_to_bytes()) return self elif mode == "OFB": cipher = DES.new(key, mode=DES.MODE_OFB, iv=iv) self.state = cipher.encrypt(self._convert_to_bytes()) return self
Example #6
Source File: secretsdump.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
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']
Example #7
Source File: lsasecrets.py From volatility with GNU General Public License v2.0 | 6 votes |
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]
Example #8
Source File: APDU.py From asterix with GNU Lesser General Public License v2.1 | 6 votes |
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]
Example #9
Source File: secretsdump.py From smbwrapper with GNU General Public License v3.0 | 6 votes |
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']
Example #10
Source File: crypto.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
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'])
Example #11
Source File: lsasecrets.py From volatility with GNU General Public License v2.0 | 6 votes |
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]
Example #12
Source File: lsasecrets.py From darkc0de-old-stuff with GNU General Public License v3.0 | 6 votes |
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]
Example #13
Source File: crypto.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
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
Example #14
Source File: lsasecrets.py From LaZagneForensic with GNU Lesser General Public License v3.0 | 6 votes |
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]
Example #15
Source File: lsasecrets.py From aumfor with GNU General Public License v3.0 | 6 votes |
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]
Example #16
Source File: lsasecrets.py From smbwrapper with GNU General Public License v3.0 | 6 votes |
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]
Example #17
Source File: lsasecrets.py From DAMM with GNU General Public License v2.0 | 6 votes |
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]
Example #18
Source File: eap.py From understanding-eap with GNU General Public License v3.0 | 6 votes |
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
Example #19
Source File: secretsdump.py From cracke-dit with MIT License | 6 votes |
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
Example #20
Source File: secretsdump.py From cracke-dit with MIT License | 6 votes |
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']
Example #21
Source File: test_DES.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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')))
Example #22
Source File: lsasecrets.py From vortessence with GNU General Public License v2.0 | 6 votes |
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]
Example #23
Source File: crypto.py From cracke-dit with MIT License | 6 votes |
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'])
Example #24
Source File: crypto.py From cracke-dit with MIT License | 6 votes |
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
Example #25
Source File: dsencryption.py From ntdsxtract with GNU General Public License v3.0 | 5 votes |
def dsDecryptSingleHash(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
Example #26
Source File: secretsdump.py From smbwrapper with GNU General Public License v3.0 | 5 votes |
def __removeDESLayer(self, cryptedHash, rid): Key1,Key2 = self.__cryptoCommon.deriveKey(int(rid)) Crypt1 = DES.new(Key1, DES.MODE_ECB) Crypt2 = DES.new(Key2, DES.MODE_ECB) decryptedHash = Crypt1.decrypt(cryptedHash[:8]) + Crypt2.decrypt(cryptedHash[8:]) return decryptedHash
Example #27
Source File: gm_app_fw.py From gmfwtools with Apache License 2.0 | 5 votes |
def des_decrypt(self, data): cipher = DES.new(self.des_key(), DES.MODE_ECB) return cipher.decrypt(data)
Example #28
Source File: hashdump.py From volatility with GNU General Public License v2.0 | 5 votes |
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
Example #29
Source File: hashdump.py From volatility with GNU General Public License v2.0 | 5 votes |
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)
Example #30
Source File: hashdump.py From smbwrapper with GNU General Public License v3.0 | 5 votes |
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