本文整理汇总了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