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


Python Padding.unpad方法代码示例

本文整理汇总了Python中Cryptodome.Util.Padding.unpad方法的典型用法代码示例。如果您正苦于以下问题:Python Padding.unpad方法的具体用法?Python Padding.unpad怎么用?Python Padding.unpad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cryptodome.Util.Padding的用法示例。


在下文中一共展示了Padding.unpad方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decrypt_credential

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def decrypt_credential(enc, secret=None):
    """
    Decodes data

    :param data: Data to be decoded
    :type data: str
    :returns:  string -- Decoded data
    """
    # pylint: disable=invalid-name,import-error
    import base64
    try:  # The crypto package depends on the library installed (see Wiki)
        from Crypto.Cipher import AES
        from Crypto.Util import Padding
    except ImportError:
        from Cryptodome.Cipher import AES
        from Cryptodome.Util import Padding
    enc = base64.b64decode(enc)
    iv = enc[:AES.block_size]
    cipher = AES.new(secret or get_crypt_key(), AES.MODE_CBC, iv)
    decoded = Padding.unpad(
        padded_data=cipher.decrypt(enc[AES.block_size:]),
        block_size=__BLOCK_SIZE__)
    return decoded 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:25,代码来源:credentials.py

示例2: test2

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def test2(self):
        padded = pad(uh(b("12345678")), 4)
        self.assertTrue(padded == uh(b("1234567804040404")))
        back = unpad(padded, 4)
        self.assertTrue(back == uh(b("12345678"))) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:7,代码来源:test_Padding.py

示例3: aes_cbc_decrypt

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def aes_cbc_decrypt(cipher_text: bytes, iv: bytes, key: bytes):
        cipher = AES.new(key=key, mode=AES.MODE_CBC, iv=iv)
        return unpad(cipher.decrypt(cipher_text), AES.block_size, style='pkcs7') 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:5,代码来源:aes_handler.py

示例4: decrypt

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def decrypt(key, enc):
        assert type(enc) == bytes, 'Encrypt data is bytes'
        if isinstance(key, str):
            key = b64decode(key.encode())
        iv = enc[:AES.block_size]
        cipher = AES.new(key, AES.MODE_CBC, iv)
        raw = cipher.decrypt(enc[AES.block_size:])
        raw = unpad(raw, AES.block_size)
        if len(raw) == 0:
            raise ValueError("AES decryption error, not correct key.")
        return raw 
开发者ID:namuyan,项目名称:p2p-python,代码行数:13,代码来源:utils.py

示例5: decrypt

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def decrypt(self, init_vector, ciphertext):
        """Decrypt a ciphertext"""
        cipher = AES.new(self.encryption_key, AES.MODE_CBC, init_vector)
        return Padding.unpad(cipher.decrypt(ciphertext), 16) 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:6,代码来源:default_crypto.py

示例6: decrypt

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def decrypt(data, key):
    payload = base64.b64decode(data)
    data = aes_decrypt(payload, key)
    # response starts with 2 random bytes, exclude them
    response = unpad(data, 16, style="pkcs7")[2:]
    return response.decode("ascii") 
开发者ID:rgerganov,项目名称:py-air-control,代码行数:8,代码来源:http_client.py

示例7: _decrypt_payload

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def _decrypt_payload(self, encrypted_payload):
        encoded_counter = encrypted_payload[0:8]
        aes = self._handle_AES(encoded_counter)
        encoded_message = encrypted_payload[8:-64].upper()
        digest = encrypted_payload[-64:]
        calculated_digest = self._create_digest(encoded_counter, encoded_message)
        if digest != calculated_digest:
            raise WrongDigestException
        decoded_message = aes.decrypt(bytes.fromhex(encoded_message))
        unpaded_message = unpad(decoded_message, 16, style="pkcs7")
        return unpaded_message.decode("utf8") 
开发者ID:rgerganov,项目名称:py-air-control,代码行数:13,代码来源:coap_client.py

示例8: _decrypt

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def _decrypt(self, data, key):
        payload = base64.b64decode(data)
        data = self._aes_decrypt(payload, key)
        # response starts with 2 random bytes, exclude them
        response = unpad(data, 16, style="pkcs7")[2:]
        return response.decode("ascii") 
开发者ID:rgerganov,项目名称:py-air-control,代码行数:8,代码来源:http_test_controller.py

示例9: _decrypt_payload

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def _decrypt_payload(self, encrypted_payload):
        self.encoded_counter = encrypted_payload[0:8]
        aes = self._handle_AES(self.encoded_counter)
        encoded_message = encrypted_payload[8:-64].upper()
        digest = encrypted_payload[-64:]
        calculated_digest = self._create_digest(self.encoded_counter, encoded_message)
        if digest != calculated_digest:
            raise Exception
        decoded_message = aes.decrypt(bytes.fromhex(encoded_message))
        unpaded_message = unpad(decoded_message, 16, style="pkcs7")
        return unpaded_message.decode("utf8") 
开发者ID:rgerganov,项目名称:py-air-control,代码行数:13,代码来源:coap_resources.py

示例10: test1

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def test1(self):
        padded = pad(b(""), 4)
        self.assertTrue(padded == uh(b("04040404")))
        padded = pad(b(""), 4, 'pkcs7')
        self.assertTrue(padded == uh(b("04040404")))
        back = unpad(padded, 4)
        self.assertTrue(back == b("")) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:9,代码来源:test_Padding.py

示例11: test3

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def test3(self):
        padded = pad(uh(b("123456")), 4)
        self.assertTrue(padded == uh(b("12345601")))
        back = unpad(padded, 4)
        self.assertTrue(back == uh(b("123456"))) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:7,代码来源:test_Padding.py

示例12: test4

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def test4(self):
        padded = pad(uh(b("1234567890")), 4)
        self.assertTrue(padded == uh(b("1234567890030303")))
        back = unpad(padded, 4)
        self.assertTrue(back == uh(b("1234567890"))) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:7,代码来源:test_Padding.py

示例13: testn3

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def testn3(self):
        self.assertRaises(ValueError, unpad, b("123456\x02"), 4)
        self.assertRaises(ValueError, unpad, b("123456\x00"), 4)
        self.assertRaises(ValueError, unpad, b("123456\x05\x05\x05\x05\x05"), 4) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:6,代码来源:test_Padding.py

示例14: testn1

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def testn1(self):
        self.assertRaises(ValueError, unpad, b("123456\x81"), 4, 'iso7816') 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:4,代码来源:test_Padding.py

示例15: test1

# 需要导入模块: from Cryptodome.Util import Padding [as 别名]
# 或者: from Cryptodome.Util.Padding import unpad [as 别名]
def test1(self):
        padded = pad(b(""), 4)
        self.failUnless(padded == uh(b("04040404")))
        padded = pad(b(""), 4, 'pkcs7')
        self.failUnless(padded == uh(b("04040404")))
        back = unpad(padded, 4)
        self.failUnless(back == b("")) 
开发者ID:mchristopher,项目名称:PokemonGo-DesktopMap,代码行数:9,代码来源:test_Padding.py


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