本文整理匯總了Python中Crypto.Cipher.XOR.new方法的典型用法代碼示例。如果您正苦於以下問題:Python XOR.new方法的具體用法?Python XOR.new怎麽用?Python XOR.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Crypto.Cipher.XOR
的用法示例。
在下文中一共展示了XOR.new方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _getCipher
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def _getCipher(self, cip, iv, key):
"""
Creates an initialized cipher object.
@param cip: the name of the cipher: maps into Crypto.Cipher.*
@param iv: the initialzation vector
@param key: the encryption key
"""
modName, keySize, counterMode = self.cipherMap[cip]
if not modName: # no cipher
return _DummyCipher()
mod = __import__('Crypto.Cipher.%s'%modName, {}, {}, 'x')
if counterMode:
return mod.new(key[:keySize], mod.MODE_CTR, iv[:mod.block_size],
counter=_Counter(iv, mod.block_size))
else:
return mod.new(key[:keySize], mod.MODE_CBC, iv[:mod.block_size])
示例2: _getMAC
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def _getMAC(self, mac, key):
"""
Gets a 4-tuple representing the message authentication code.
(<hash module>, <inner hash value>, <outer hash value>,
<digest size>)
@param mac: a key mapping into macMap
@type mac: C{str}
@param key: the MAC key.
@type key: C{str}
"""
mod = self.macMap[mac]
if not mod:
return (None, '', '', 0)
ds = mod().digest_size
key = key[:ds] + '\x00' * (64 - ds)
i = XOR.new('\x36').encrypt(key)
o = XOR.new('\x5c').encrypt(key)
return mod, i, o, ds
示例3: __call__
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def __call__(self):
"""
Increment the counter and return the new value.
"""
i = self.len
while i > -1:
self.count[i] = n = chr((ord(self.count[i]) + 1) % 256)
if n == '\x00':
i -= 1
else:
return self.count.tostring()
self.count = array.array('c', '\x00' * self.blockSize)
return self.count.tostring()
# Diffie-Hellman primes from Oakley Group 2 [RFC 2409]
示例4: _continueGEX_GROUP
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def _continueGEX_GROUP(self, ignored, pubKey, f, signature):
serverKey = keys.getPublicKeyObject(pubKey)
sharedSecret = _MPpow(f, self.x, DH_PRIME)
h = sha.new()
h.update(NS(self.ourVersionString))
h.update(NS(self.otherVersionString))
h.update(NS(self.ourKexInitPayload))
h.update(NS(self.serverKexInitPayload))
h.update(NS(pubKey))
h.update(MP(self.DHpubKey))
h.update(MP(f))
h.update(sharedSecret)
exchangeHash = h.digest()
if not keys.verifySignature(serverKey, signature, exchangeHash):
self.sendDisconnect(DISCONNECT_KEY_EXCHANGE_FAILED, 'bad signature')
return
self._keySetup(sharedSecret, exchangeHash)
示例5: _continueGEX_REPLY
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def _continueGEX_REPLY(self, ignored, pubKey, f, signature):
serverKey = keys.getPublicKeyObject(pubKey)
sharedSecret = _MPpow(f, self.x, self.p)
h = sha.new()
h.update(NS(self.ourVersionString))
h.update(NS(self.otherVersionString))
h.update(NS(self.ourKexInitPayload))
h.update(NS(self.serverKexInitPayload))
h.update(NS(pubKey))
h.update('\x00\x00\x08\x00')
h.update(MP(self.p))
h.update(MP(self.g))
h.update(MP(self.DHpubKey))
h.update(MP(f))
h.update(sharedSecret)
exchangeHash = h.digest()
if not keys.verifySignature(serverKey, signature, exchangeHash):
self.sendDisconnect(DISCONNECT_KEY_EXCHANGE_FAILED, 'bad signature')
return
self._keySetup(sharedSecret, exchangeHash)
示例6: decode_stream
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def decode_stream(fn):
data = open(fn, 'rb').read()
port = int(fn[-5:])
if port not in keys or port == 4444: # We don't bother with commands - already have them
return False
pt = fn.find('-')
seq = int(fn[pt-5:pt]) # Use source port as sequence number
# find the key
key = keys[port]
data = XOR.new(key.decode('hex')).decrypt(data) # Remove stmedit layer
fl = names[port] % seq
size = struct.unpack('<L', data[:4])[0]
# print hex(size), hex(len(data[4:size])), hex(len(data))
if port == 7777:
# Bitmaps don't go through cryptodll
ptext = data[4:size]
else:
ptext = decrypt_data(data[4:size]) # Don't forget to trim the stmedit leaked data
if ptext is None:
print 'Failed to decrypt: %05d -> %05d' % (seq, port)
else:
open(os.path.join('traffic/', fl), 'wb').write(ptext)
示例7: main
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def main():
ports = map(str, [ x * 1111 for x in [ 6, 7, 8 ] ]) # omitting port 4444
sdir = 'streams'
keys = {}
for fn in os.listdir(sdir):
if len(fn) < 5 or fn[-5] != '0':
continue
port = fn[-4:]
if port not in ports:
continue
key = getkey(os.path.join(sdir, fn))
if key is None:
print '%s: getkey() failed' % fn
continue
if port in keys:
if key != keys[port]:
print '%s: new key: %s' % (port, key.encode('hex'))
else:
print '%s: key: %s' % (port, key.encode('hex'))
keys[port] = key
示例8: decrypt_xor
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def decrypt_xor(key, data):
cipher = XOR.new(key)
return cipher.decrypt(data)
# RC4
示例9: decrypt_arc4
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def decrypt_arc4(key, data):
cipher = ARC4.new(key)
return cipher.decrypt(data)
# DES
示例10: decrypt_des_ecb
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [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)
示例11: decrypt_des_cbc
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def decrypt_des_cbc(key, data, iv=None):
mode = DES.MODE_CBC
if iv:
cipher = DES.new(key, mode, iv)
else:
cipher = DES.new(key, mode)
return cipher.decrypt(data)
# DES3
示例12: decrypt_des3
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def decrypt_des3(key, data):
cipher = DES3.new(key)
return cipher.decrypt(data)
# AES
示例13: decrypt_aes_cbc_iv
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def decrypt_aes_cbc_iv(key, iv, data):
mode = AES.MODE_CBC
cipher = AES.new(key, mode, IV=iv)
return cipher.decrypt(data)
# Blowfish
示例14: decrypt_blowfish
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def decrypt_blowfish(key, data):
cipher = Blowfish.new(key)
return cipher.decrypt(data)
# RC6 - Custom
示例15: runTest
# 需要導入模塊: from Crypto.Cipher import XOR [as 別名]
# 或者: from Crypto.Cipher.XOR import new [as 別名]
def runTest(self):
"""33-byte key (should raise ValueError under current implementation)"""
# Crypto.Cipher.XOR previously truncated its inputs at 32 bytes. Now
# it should raise a ValueError if the length is too long.
self.assertRaises(ValueError, XOR.new, "x"*33)