當前位置: 首頁>>代碼示例>>Python>>正文


Python algorithms.TripleDES方法代碼示例

本文整理匯總了Python中cryptography.hazmat.primitives.ciphers.algorithms.TripleDES方法的典型用法代碼示例。如果您正苦於以下問題:Python algorithms.TripleDES方法的具體用法?Python algorithms.TripleDES怎麽用?Python algorithms.TripleDES使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cryptography.hazmat.primitives.ciphers.algorithms的用法示例。


在下文中一共展示了algorithms.TripleDES方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: cipher

# 需要導入模塊: from cryptography.hazmat.primitives.ciphers import algorithms [as 別名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES [as 別名]
def cipher(self):
        bs = {SymmetricKeyAlgorithm.IDEA: algorithms.IDEA,
              SymmetricKeyAlgorithm.TripleDES: algorithms.TripleDES,
              SymmetricKeyAlgorithm.CAST5: algorithms.CAST5,
              SymmetricKeyAlgorithm.Blowfish: algorithms.Blowfish,
              SymmetricKeyAlgorithm.AES128: algorithms.AES,
              SymmetricKeyAlgorithm.AES192: algorithms.AES,
              SymmetricKeyAlgorithm.AES256: algorithms.AES,
              SymmetricKeyAlgorithm.Twofish256: namedtuple('Twofish256', ['block_size'])(block_size=128),
              SymmetricKeyAlgorithm.Camellia128: algorithms.Camellia,
              SymmetricKeyAlgorithm.Camellia192: algorithms.Camellia,
              SymmetricKeyAlgorithm.Camellia256: algorithms.Camellia}

        if self in bs:
            return bs[self]

        raise NotImplementedError(repr(self)) 
開發者ID:SecurityInnovation,項目名稱:PGPy,代碼行數:19,代碼來源:constants.py

示例2: key_size

# 需要導入模塊: from cryptography.hazmat.primitives.ciphers import algorithms [as 別名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES [as 別名]
def key_size(self):
        ks = {SymmetricKeyAlgorithm.IDEA: 128,
              SymmetricKeyAlgorithm.TripleDES: 192,
              SymmetricKeyAlgorithm.CAST5: 128,
              SymmetricKeyAlgorithm.Blowfish: 128,
              SymmetricKeyAlgorithm.AES128: 128,
              SymmetricKeyAlgorithm.AES192: 192,
              SymmetricKeyAlgorithm.AES256: 256,
              SymmetricKeyAlgorithm.Twofish256: 256,
              SymmetricKeyAlgorithm.Camellia128: 128,
              SymmetricKeyAlgorithm.Camellia192: 192,
              SymmetricKeyAlgorithm.Camellia256: 256}

        if self in ks:
            return ks[self]

        raise NotImplementedError(repr(self)) 
開發者ID:SecurityInnovation,項目名稱:PGPy,代碼行數:19,代碼來源:constants.py

示例3: __init__

# 需要導入模塊: from cryptography.hazmat.primitives.ciphers import algorithms [as 別名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES [as 別名]
def __init__(
      self, cipher_mode=None, initialization_vector=None, key=None, **kwargs):
    """Initializes a decrypter.

    Args:
      cipher_mode (Optional[str]): cipher mode.
      initialization_vector (Optional[bytes]): initialization vector.
      key (Optional[bytes]): key.
      kwargs (dict): keyword arguments depending on the decrypter.

    Raises:
      ValueError: when key is not set or the cipher mode is not supported.
    """
    if not key:
      raise ValueError('Missing key.')

    if cipher_mode not in self._ENCRYPTION_MODES:
      raise ValueError('Unsupported cipher mode: {0!s}'.format(cipher_mode))

    algorithm = algorithms.TripleDES(key)

    super(DES3Decrypter, self).__init__(
        algorithm=algorithm, cipher_mode=cipher_mode,
        initialization_vector=initialization_vector, **kwargs) 
開發者ID:log2timeline,項目名稱:dfvfs,代碼行數:26,代碼來源:des3_decrypter.py

示例4: _DecryptTripleDES

# 需要導入模塊: from cryptography.hazmat.primitives.ciphers import algorithms [as 別名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES [as 別名]
def _DecryptTripleDES(self, key, data):
    """Decrypts Triple DES-ECB encrypted data.

    Args:
      key (str): key used to decrypt the data.
      data (bytes): data to decrypt.

    Returns:
      bytes: decrypted data.
    """
    algorithm = algorithms.TripleDES(key)
    mode = modes.ECB()
    backend = backends.default_backend()
    cipher = ciphers.Cipher(algorithm, mode=mode, backend=backend)
    cipher_context = cipher.decryptor()
    return cipher_context.update(data) 
開發者ID:libyal,項目名稱:winreg-kb,代碼行數:18,代碼來源:cached_credentials.py

示例5: setup_cipher

# 需要導入模塊: from cryptography.hazmat.primitives.ciphers import algorithms [as 別名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES [as 別名]
def setup_cipher(self):
		algorithm = algorithms.TripleDES(self.key)
		self._cipher = Cipher(algorithm, mode=self.IV, backend=default_backend())
		self.encryptor = self._cipher.encryptor()
		self.decryptor = self._cipher.decryptor() 
開發者ID:skelsec,項目名稱:msldap,代碼行數:7,代碼來源:TDES.py

示例6: decrypt_smime_content

# 需要導入模塊: from cryptography.hazmat.primitives.ciphers import algorithms [as 別名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES [as 別名]
def decrypt_smime_content(payload: bytes, key: rsa.RSAPrivateKey) -> bytes:
    content_info = ContentInfo.load(payload)

    assert content_info['content_type'].native == 'enveloped_data'
    content: EnvelopedData = content_info['content']

    matching_recipient = content['recipient_infos'][0]

    # Need to see if we hold the key for any valid recipient.
    # for recipient_info in content['recipient_infos']:
    #     assert recipient_info.name == 'ktri'  # Only support KeyTransRecipientInfo
    #     ktri: KeyTransRecipientInfo = recipient_info.chosen
    #     recipient_id: RecipientIdentifier = ktri['rid']
    #     assert recipient_id.name == 'issuer_and_serial_number'  # Only support IssuerAndSerialNumber
    #     matching_recipient = recipient_info

    encryption_algo = matching_recipient.chosen['key_encryption_algorithm'].native
    encrypted_key = matching_recipient.chosen['encrypted_key'].native

    assert encryption_algo['algorithm'] == 'rsa'

    # Get the content key
    plain_key = key.decrypt(
        encrypted_key,
        padding=padding.PKCS1v15(),
    )

    # Now we have the plain key, we can decrypt the encrypted data
    encrypted_contentinfo = content['encrypted_content_info']

    algorithm: EncryptionAlgorithm = encrypted_contentinfo['content_encryption_algorithm']  #: EncryptionAlgorithm
    encrypted_content_bytes = encrypted_contentinfo['encrypted_content'].native

    symkey = None

    if algorithm.encryption_cipher == 'aes':
        symkey = AES(plain_key)
    elif algorithm.encryption_cipher == 'tripledes':
        symkey = TripleDES(plain_key)
    else:
        print('Dont understand encryption cipher: ', algorithm.encryption_cipher)

    cipher = Cipher(symkey, modes.CBC(algorithm.encryption_iv), backend=default_backend())
    decryptor = cipher.decryptor()

    decrypted_data = decryptor.update(encrypted_content_bytes) + decryptor.finalize()
    return decrypted_data 
開發者ID:cmdmnt,項目名稱:commandment,代碼行數:49,代碼來源:smime.py


注:本文中的cryptography.hazmat.primitives.ciphers.algorithms.TripleDES方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。