本文整理匯總了Python中Crypto.Cipher.DES3屬性的典型用法代碼示例。如果您正苦於以下問題:Python Cipher.DES3屬性的具體用法?Python Cipher.DES3怎麽用?Python Cipher.DES3使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類Crypto.Cipher
的用法示例。
在下文中一共展示了Cipher.DES3屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_new_negative
# 需要導入模塊: from Crypto import Cipher [as 別名]
# 或者: from Crypto.Cipher import DES3 [as 別名]
def test_new_negative(self):
from Crypto.Cipher import DES3
self.assertRaises(ValueError, Poly1305.new, key=self.key[:31], cipher=AES)
self.assertRaises(ValueError, Poly1305.new, key=self.key, cipher=DES3)
self.assertRaises(ValueError, Poly1305.new, key=self.key, nonce=b'1' * 15, cipher=AES)
self.assertRaises(TypeError, Poly1305.new, key=u"2" * 32, cipher=AES)
self.assertRaises(TypeError, Poly1305.new, key=self.key, data=u"2" * 100, cipher=AES)
示例2: test2
# 需要導入模塊: from Crypto import Cipher [as 別名]
# 或者: from Crypto.Cipher import DES3 [as 別名]
def test2(self):
"""Verify that no more than 127(AES) and 63(TDES)
components are accepted."""
key = bchr(0) * 8 + bchr(255) * 8
for module in (AES, DES3):
s2v = _S2V.new(key, module)
max_comps = module.block_size*8-1
for i in range(max_comps):
s2v.update(b("XX"))
self.assertRaises(TypeError, s2v.update, b("YY"))
示例3: recrypt
# 需要導入模塊: from Crypto import Cipher [as 別名]
# 或者: from Crypto.Cipher import DES3 [as 別名]
def recrypt(self, oldPassPhrase, newPassPhrase = None, _salt = None):
if newPassPhrase is None and self.s2k == ENCRYPTION_TYPE_UNENCRYPTED:
# Nothing to do here
return False
if oldPassPhrase == newPassPhrase:
# Nothing to do either
return False
# decrypt the MPIs
mpis = self.decrypt(oldPassPhrase)
stream = util.ExtendedStringIO()
for mpi in mpis:
self._writeMPI(stream, mpi)
if newPassPhrase is None:
self.s2k = ENCRYPTION_TYPE_UNENCRYPTED
self.salt = None
self._writeBin(stream,
int2ToBytes(computeRFC2440Checksum(stream.getvalue())))
else:
self.s2k = ENCRYPTION_TYPE_SHA1_CHECK
stream.write(computeSHAChecksum(stream.getvalue()))
# DES3
self.symmEncAlg = 2
# We force iterated + salted
self.s2kType = 0x03
# SHA1 protection
self.hashAlg = 2
# Iterate 96 times (seems pretty standard)
self.count = 96
if isinstance(self, PGP_SecretSubKey):
# Use the same salt as the main key
self.salt = _salt
else:
self.salt = file("/dev/urandom").read(8)
stream.seek(0)
io = self._encryptStream(stream, newPassPhrase)
stream = io
self.encMpiFile = stream
stream.seek(0)
# Re-crypt subkeys too
for sk in self.iterSubKeys():
if isinstance(sk, PGP_SecretSubKey):
sk.recrypt(oldPassPhrase, newPassPhrase, _salt = self.salt)
sk._rewritePacket()
return True