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


Python AES.MODE_GCM属性代码示例

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


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

示例1: test_mac_len

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def test_mac_len(self):
        # Invalid MAC length
        self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_GCM,
                          nonce=self.nonce_96, mac_len=3)
        self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_GCM,
                          nonce=self.nonce_96, mac_len=16+1)

        # Valid MAC length
        for mac_len in range(5, 16 + 1):
            cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96,
                             mac_len=mac_len)
            _, mac = cipher.encrypt_and_digest(self.data_128)
            self.assertEqual(len(mac), mac_len)

        # Default MAC length
        cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96)
        _, mac = cipher.encrypt_and_digest(self.data_128)
        self.assertEqual(len(mac), 16) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:20,代码来源:test_GCM.py

示例2: test_valid_multiple_encrypt_or_decrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def test_valid_multiple_encrypt_or_decrypt(self):
        for method_name in "encrypt", "decrypt":
            for auth_data in (None, b("333"), self.data_128,
                              self.data_128 + b("3")):
                if auth_data is None:
                    assoc_len = None
                else:
                    assoc_len = len(auth_data)
                cipher = AES.new(self.key_128, AES.MODE_GCM,
                                 nonce=self.nonce_96)
                if auth_data is not None:
                    cipher.update(auth_data)
                method = getattr(cipher, method_name)
                method(self.data_128)
                method(self.data_128)
                method(self.data_128)
                method(self.data_128) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:19,代码来源:test_GCM.py

示例3: test_invalid_decrypt_or_update_after_verify

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def test_invalid_decrypt_or_update_after_verify(self):
        cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96)
        ct = cipher.encrypt(self.data_128)
        mac = cipher.digest()

        for method_name in "decrypt", "update":
            cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96)
            cipher.decrypt(ct)
            cipher.verify(mac)
            self.assertRaises(TypeError, getattr(cipher, method_name),
                              self.data_128)

            cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96)
            cipher.decrypt_and_verify(ct, mac)
            self.assertRaises(TypeError, getattr(cipher, method_name),
                              self.data_128) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:18,代码来源:test_GCM.py

示例4: test_2

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def test_2(self):
        key = unhexlify("843ffcf5d2b72694d19ed01d01249412")
        iv  = unhexlify("dbcca32ebf9b804617c3aa9e")
        aad = unhexlify("00000000000000000000000000000000" +
                        "101112131415161718191a1b1c1d1e1f")
        pt  = unhexlify("000102030405060708090a0b0c0d0e0f" +
                        "101112131415161718191a1b1c1d1e1f" +
                        "202122232425262728292a2b2c2d2e2f" +
                        "303132333435363738393a3b3c3d3e3f" +
                        "404142434445464748494a4b4c4d4e4f")
        ct  = unhexlify("6268c6fa2a80b2d137467f092f657ac0" +
                        "4d89be2beaa623d61b5a868c8f03ff95" +
                        "d3dcee23ad2f1ab3a6c80eaf4b140eb0" +
                        "5de3457f0fbc111a6b43d0763aa422a3" +
                        "013cf1dc37fe417d1fbfc449b75d4cc5")
        digest = unhexlify("3b629ccfbc1119b7319e1dce2cd6fd6d")

        cipher = AES.new(key, AES.MODE_GCM, iv).update(aad)
        ct2, digest2 = cipher.encrypt_and_digest(pt)

        self.assertEqual(ct, ct2)
        self.assertEqual(digest, digest2) 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:24,代码来源:test_GCM.py

示例5: test_mac_len

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def test_mac_len(self):
        # Invalid MAC length
        self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_GCM,
                          nonce=self.nonce_96, mac_len=3)
        self.assertRaises(ValueError, AES.new, self.key_128, AES.MODE_GCM,
                          nonce=self.nonce_96, mac_len=16+1)

        # Valid MAC length
        for mac_len in xrange(5, 16 + 1):
            cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96,
                             mac_len=mac_len)
            _, mac = cipher.encrypt_and_digest(self.data_128)
            self.assertEqual(len(mac), mac_len)

        # Default MAC length
        cipher = AES.new(self.key_128, AES.MODE_GCM, nonce=self.nonce_96)
        _, mac = cipher.encrypt_and_digest(self.data_128)
        self.assertEqual(len(mac), 16) 
开发者ID:mchristopher,项目名称:PokemonGo-DesktopMap,代码行数:20,代码来源:test_GCM.py

示例6: aes_gcm_encrypt_with_iv

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def aes_gcm_encrypt_with_iv(plain_text: bytes, hdr: bytes, key: bytes, iv: bytes):
        cipher = AES.new(key=key, mode=AES.MODE_GCM, nonce=iv)
        cipher.update(hdr)
        cipher_text, mac_tag = cipher.encrypt_and_digest(plain_text)
        return mac_tag, cipher_text 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:7,代码来源:aes_handler.py

示例7: aes_gcm_decrypt_with_iv

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def aes_gcm_decrypt_with_iv(cipher_text: bytes, hdr: bytes, mac_tag: bytes, key: bytes, iv: bytes) -> bytes:
        cipher = AES.new(key=key, mode=AES.MODE_GCM, nonce=iv)
        cipher.update(hdr)
        try:
            plain_text = cipher.decrypt_and_verify(cipher_text, mac_tag)
        except ValueError:
            plain_text = b""
        except KeyError:
            plain_text = b""
        return plain_text 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:12,代码来源:aes_handler.py

示例8: aes_gcm_encrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def aes_gcm_encrypt(plain_text: bytes, hdr: bytes, key: bytes):
        cipher = AES.new(key=key, mode=AES.MODE_GCM)
        cipher.update(hdr)
        cipher_text, mac_tag = cipher.encrypt_and_digest(plain_text)
        nonce = cipher.nonce
        return nonce, mac_tag, cipher_text 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:8,代码来源:aes_handler.py

示例9: aes_gcm_decrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def aes_gcm_decrypt(cipher_text: bytes, hdr: bytes, nonce: bytes, mac_tag: bytes, key: bytes):
        cipher = AES.new(key=key, mode=AES.MODE_GCM, nonce=nonce)
        cipher.update(hdr)
        try:
            plain_text = cipher.decrypt_and_verify(cipher_text, mac_tag)
        except ValueError:
            plain_text = b""
        except KeyError:
            plain_text = b""
        return plain_text 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:12,代码来源:aes_handler.py

示例10: main

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def main():
  parser = argparse.ArgumentParser(description="Decrypt mRemoteNG passwords.")
  group = parser.add_mutually_exclusive_group()
  group.add_argument("-f", "--file", help="name of file containing mRemoteNG password")
  group.add_argument("-s", "--string", help="base64 string of mRemoteNG password")
  parser.add_argument("-p", "--password", help="Custom password", default="mR3m")

  if len(sys.argv) < 2:
    parser.print_help(sys.stderr)
    sys.exit(1)

  args = parser.parse_args()
  encrypted_data = ""
  if args.file != None:
    with open(args.file) as f:
      encrypted_data = f.read()
      encrypted_data = encrypted_data.strip()
      encrypted_data = base64.b64decode(encrypted_data)

  elif args.string != None:
    encrypted_data = args.string
    encrypted_data = base64.b64decode(encrypted_data)

  else:
    print("Please use either the file (-f, --file) or string (-s, --string) flag")
    sys.exit(1)

  salt = encrypted_data[:16]
  associated_data = encrypted_data[:16]
  nonce = encrypted_data[16:32]
  ciphertext = encrypted_data[32:-16]
  tag = encrypted_data[-16:]
  key = hashlib.pbkdf2_hmac("sha1", args.password.encode(), salt, 1000, dklen=32)

  cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
  cipher.update(associated_data)
  plaintext = cipher.decrypt_and_verify(ciphertext, tag)
  print("Password: {}".format(plaintext.decode("utf-8"))) 
开发者ID:haseebT,项目名称:mRemoteNG-Decrypt,代码行数:40,代码来源:mremoteng_decrypt.py

示例11: encrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def encrypt(plaintext, key):
    #Deal with the case when field is empty
    if plaintext is None:
        plaintext = b''

    nonce = get_random_bytes(AES.block_size)
    cipher = AES.new(key, AES.MODE_GCM, nonce = nonce)
    (cipher_text, digest) = cipher.encrypt_and_digest(_pad(plaintext))
    return base64.b64encode(nonce + cipher_text + digest) 
开发者ID:keylime,项目名称:keylime,代码行数:11,代码来源:cryptodome.py

示例12: decrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def decrypt(ciphertext, key):

    ciphertext = base64.b64decode(ciphertext)

    #error handling
    _has_iv_material(ciphertext)
    _is_multiple_16(ciphertext)

    nonce = ciphertext[:AES.block_size]
    digest = ciphertext[-AES.block_size:]
    cipher = AES.new(key, AES.MODE_GCM, nonce = nonce)
    cipher_text = bytes(ciphertext[AES.block_size:-AES.block_size])
    return _strip_pad(cipher.decrypt_and_verify(cipher_text, digest)) 
开发者ID:keylime,项目名称:keylime,代码行数:15,代码来源:cryptodome.py

示例13: encrypt_aes

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def encrypt_aes(data, key):
    # type: (bytes, bytes) -> bytes
    iv = os.urandom(12)
    cipher = AES.new(key=key, mode=AES.MODE_GCM, nonce=iv)
    enc_data, tag = cipher.encrypt_and_digest(data)
    return iv + enc_data + tag 
开发者ID:Keeper-Security,项目名称:Commander,代码行数:8,代码来源:rest_api.py

示例14: decrypt_aes

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def decrypt_aes(data, key):
    # type: (bytes, bytes) -> bytes
    cipher = AES.new(key=key, mode=AES.MODE_GCM, nonce=data[:12])
    return cipher.decrypt_and_verify(data[12:-16], data[-16:]) 
开发者ID:Keeper-Security,项目名称:Commander,代码行数:6,代码来源:rest_api.py

示例15: create_meta_cipher

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import MODE_GCM [as 别名]
def create_meta_cipher(secret):
    meta_key = hkdf(16, secret, info=b'metadata')
    return AES.new(meta_key, AES.MODE_GCM, b'\x00' * 12, mac_len=16) 
开发者ID:nneonneo,项目名称:ffsend,代码行数:5,代码来源:ffsend.py


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