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


Python OpenSSL.get_cipher方法代码示例

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


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

示例1: decrypt

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
 def decrypt(self, data, ciphername="aes-256-cbc"):
     """
     Decrypt data with ECIES method using the local private key
     """
     blocksize = OpenSSL.get_cipher(ciphername).get_blocksize()
     iv = data[:blocksize]
     i = blocksize
     curve, pubkey_x, pubkey_y, i2 = ECC._decode_pubkey(data[i:])
     i += i2
     ciphertext = data[i : len(data) - 32]
     i += len(ciphertext)
     mac = data[i:]
     key = sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
     key_e, key_m = key[:32], key[32:]
     """
     pyelliptic was changed slightly so that the hmac covers the
     iv and pubkey. So let's have an upgrade period where we support
     both the old and the new hmac'ing algorithms.
     https://github.com/yann2192/pyelliptic/issues/17
     """
     if hmac_sha256(key_m, ciphertext) != mac:
         if hmac_sha256(key_m, data[: len(data) - 32]) != mac:
             raise RuntimeError("Fail to verify data")
     ctx = Cipher(key_e, iv, 0, ciphername)
     return ctx.ciphering(ciphertext)
开发者ID:JonathanCoe,项目名称:PyBitmessage,代码行数:27,代码来源:ecc.py

示例2: __init__

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
 def __init__(self, key, iv, do, ciphername='aes-256-cbc'):
     """
     do == 1 => Encrypt; do == 0 => Decrypt
     """
     self.cipher = OpenSSL.get_cipher(ciphername)
     self.ctx = OpenSSL.EVP_CIPHER_CTX_new()
     if do == 1 or do == 0:
         k = OpenSSL.malloc(key, len(key))
         IV = OpenSSL.malloc(iv, len(iv))
         OpenSSL.EVP_CipherInit_ex(
             self.ctx, self.cipher.get_pointer(), 0, k, IV, do)
     else:
         raise Exception("RTFM ...")
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:15,代码来源:cipher.py

示例3: raw_encrypt

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
 def raw_encrypt(data, pubkey_x, pubkey_y, curve='sect283r1',
                 ephemcurve=None, ciphername='aes-256-cbc'):
     if ephemcurve is None:
         ephemcurve = curve
     ephem = ECC(curve=ephemcurve)
     key = sha512(ephem.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
     key_e, key_m = key[:32], key[32:]
     pubkey = ephem.get_pubkey()
     iv = OpenSSL.rand(OpenSSL.get_cipher(ciphername).get_blocksize())
     ctx = Cipher(key_e, iv, 1, ciphername)
     ciphertext = ctx.ciphering(data)
     mac = hmac_sha256(key_m, ciphertext)
     return iv + pubkey + ciphertext + mac
开发者ID:AntonioReyes,项目名称:darkmarket,代码行数:15,代码来源:ecc.py

示例4: raw_encrypt

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
 def raw_encrypt(data, pubkey_x, pubkey_y, curve="sect283r1", ephemcurve=None, ciphername="aes-256-cbc"):
     if ephemcurve is None:
         ephemcurve = curve
     ephem = ECC(curve=ephemcurve)
     key = sha512(ephem.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
     key_e, key_m = key[:32], key[32:]
     pubkey = ephem.get_pubkey()
     iv = OpenSSL.rand(OpenSSL.get_cipher(ciphername).get_blocksize())
     ctx = Cipher(key_e, iv, 1, ciphername)
     ciphertext = ctx.ciphering(data)
     # ciphertext = iv + pubkey + ctx.ciphering(data) # We will switch to this line after an upgrade period
     mac = hmac_sha256(key_m, ciphertext)
     return iv + pubkey + ciphertext + mac
开发者ID:JonathanCoe,项目名称:PyBitmessage,代码行数:15,代码来源:ecc.py

示例5: decrypt

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
 def decrypt(self, data, ciphername='aes-256-cbc'):
     """
     Decrypt data with ECIES method using the local private key
     """
     blocksize = OpenSSL.get_cipher(ciphername).get_blocksize()
     iv = data[:blocksize]
     i = blocksize
     curve, pubkey_x, pubkey_y, i2 = ECC._decode_pubkey(data[i:])
     i += i2
     ciphertext = data[i:len(data)-32]
     i += len(ciphertext)
     mac = data[i:]
     key = sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
     key_e, key_m = key[:32], key[32:]
     if hmac_sha256(key_m, ciphertext) != mac:
         raise RuntimeError("Fail to verify data")
     ctx = Cipher(key_e, iv, 0, ciphername)
     return ctx.ciphering(ciphertext)
开发者ID:AntonioReyes,项目名称:darkmarket,代码行数:20,代码来源:ecc.py

示例6: __init__

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
    def __init__(self, key, iv, do, ciphername='aes-256-cbc', padding=True):
        """
        do == 1 => Encrypt; do == 0 => Decrypt
        """
        assert do in [self.ENCRYPT, self.DECRYPT], "Argument 'do' out of scope"
        self.cipher = OpenSSL.get_cipher(ciphername)
        self.ctx = OpenSSL.EVP_CIPHER_CTX_new()

        keysize = self.cipher.get_keysize()
        assert keysize is None or len(key) == keysize
        assert len(iv) == self.cipher.get_blocksize()

        k = OpenSSL.malloc(key, len(key))
        IV = OpenSSL.malloc(iv, len(iv))
        OpenSSL.EVP_CipherInit_ex(
            self.ctx, self.cipher.get_pointer(), 0, k, IV, do)

        if padding is False:
            # By default PKCS padding is enabled. This case disables it.
            OpenSSL.EVP_CIPHER_CTX_set_padding(self.ctx, 0)
开发者ID:blaa,项目名称:PyBitmessage,代码行数:22,代码来源:cipher.py

示例7: raw_encrypt

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
    def raw_encrypt(data, pubkey_x, pubkey_y, curve="sect283r1", ephemcurve=None, ciphername="aes-256-cbc"):
        if ephemcurve is None:
            ephemcurve = curve
        ephem = ECC(curve=ephemcurve)
        key = sha512(ephem.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
        key_e, key_m = key[:32], key[32:]
        pubkey = ephem.get_pubkey()
        iv = OpenSSL.rand(OpenSSL.get_cipher(ciphername).get_blocksize())
        ctx = Cipher(key_e, iv, 1, ciphername)
        import time

        if int(time.time()) < 1416175200:  # Sun, 16 Nov 2014 22:00:00 GMT
            ciphertext = ctx.ciphering(data)
        else:
            ciphertext = (
                iv + pubkey + ctx.ciphering(data)
            )  # Everyone should be using this line after the Bitmessage protocol v3 upgrade period
        mac = hmac_sha256(key_m, ciphertext)
        if int(time.time()) < 1416175200:  # Sun, 16 Nov 2014 22:00:00 GMT
            return iv + pubkey + ciphertext + mac
        else:
            return (
                ciphertext + mac
            )  # Everyone should be using this line after the Bitmessage protocol v3 upgrade period
开发者ID:votesapp,项目名称:PyBitmessageVote,代码行数:26,代码来源:ecc.py

示例8: gen_IV

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
 def gen_IV(ciphername):
     cipher = OpenSSL.get_cipher(ciphername)
     return OpenSSL.rand(cipher.get_blocksize())
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:5,代码来源:cipher.py

示例9: get_blocksize

# 需要导入模块: from pyelliptic.openssl import OpenSSL [as 别名]
# 或者: from pyelliptic.openssl.OpenSSL import get_cipher [as 别名]
 def get_blocksize(ciphername):
     cipher = OpenSSL.get_cipher(ciphername)
     return cipher.get_blocksize()
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:5,代码来源:cipher.py


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