当前位置: 首页>>代码示例>>Python>>正文


Python Cipher.DES3属性代码示例

本文整理汇总了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) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:10,代码来源:test_Poly1305.py

示例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")) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:12,代码来源:test_KDF.py

示例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 
开发者ID:sassoftware,项目名称:conary,代码行数:47,代码来源:openpgpfile.py


注:本文中的Crypto.Cipher.DES3属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。