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


Python pyaes.AESModeOfOperationCBC方法代码示例

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


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

示例1: _decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def _decrypt(password: str, salt: bytes, data: bytes, n: int, iv: bytes) -> bytes:
    """
    Decryption schema for private keys
    :param password: plaintext password used for encryption
    :param salt: password hashing salt
    :param data: encrypted data string
    :param n: length of original plaintext data
    :param iv: initialisation vector for aes
    :return: decrypted data as plaintext
    """
    # Hash password
    hashed_pass = pbkdf2_hmac('sha256', password.encode(), salt, 2000000)

    # Decrypt data, noting original length
    aes = pyaes.AESModeOfOperationCBC(hashed_pass, iv=iv)

    decrypted = b''
    while len(data):
        decrypted += aes.decrypt(data[:16])
        data = data[16:]
    decrypted_data = decrypted[:n]

    # Return original data
    return decrypted_data 
开发者ID:fetchai,项目名称:ledger-api-py,代码行数:26,代码来源:entity.py

示例2: decrypt_data

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def decrypt_data(key, data):
    decrypter = Decrypter(AESModeOfOperationCBC(key, iv=data[:16]))
    plain = decrypter.feed(data[16:])
    plain += decrypter.feed()
    return plain 
开发者ID:JoinMarket-Org,项目名称:joinmarket-clientserver,代码行数:7,代码来源:convert_old_wallet.py

示例3: _decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def _decrypt(self, value, encrypted_value):
        """Decrypt encoded cookies
        """

        if sys.platform == 'win32':
            try:
                return self._decrypt_windows_chrome(value, encrypted_value)

            # Fix for change in Chrome 80
            except RuntimeError:  # Failed to decrypt the cipher text with DPAPI
                if not self.key:
                    raise RuntimeError(
                        'Failed to decrypt the cipher text with DPAPI and no AES key.')
                # Encrypted cookies should be prefixed with 'v10' according to the
                # Chromium code. Strip it off.
                encrypted_value = encrypted_value[3:]
                nonce, tag = encrypted_value[:12], encrypted_value[-16:]
                aes = AES.new(self.key, AES.MODE_GCM, nonce=nonce)

                data = aes.decrypt_and_verify(encrypted_value[12:-16], tag)
                return data.decode()

        if value or (encrypted_value[:3] not in [b'v11', b'v10']):
            return value

        # Encrypted cookies should be prefixed with 'v10' according to the
        # Chromium code. Strip it off.
        encrypted_value = encrypted_value[3:]
        encrypted_value_half_len = int(len(encrypted_value) / 2)

        cipher = pyaes.Decrypter(
            pyaes.AESModeOfOperationCBC(self.key, self.iv))
        decrypted = cipher.feed(encrypted_value[:encrypted_value_half_len])
        decrypted += cipher.feed(encrypted_value[encrypted_value_half_len:])
        decrypted += cipher.feed()
        return decrypted.decode("utf-8") 
开发者ID:borisbabic,项目名称:browser_cookie3,代码行数:38,代码来源:__init__.py

示例4: proceed

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def proceed(self):

        key = self._getvalue(str(self.ui.op.currentText()), str(self.ui.key.text()))
        iv = self._getvalue(str(self.ui.op_iv.currentText()), str(self.ui.iv.text()))
  
        if len(key) not in [16, 24, 32]:
            self.ui.label_key.setStyleSheet("QLabel {color : red; }")
            return False

        if len(iv) != 16:
            self.ui.label_iv.setStyleSheet("QLabel {color : red; }")
            return False

        aesop = str(self.ui.op_aes.currentText())

        if self.viewMode.selector.getCurrentSelection():
            u, v = self.viewMode.selector.getCurrentSelection()

            #aes = pyaes.AESModeOfOperationCFB(key, iv = iv, segment_size = 1)

            # we support only CBC now
            aes = pyaes.AESModeOfOperationCBC(key, iv)
            plaintext =  self.dataModel.getStream(u, v)

            # damn!
            blocks = len(plaintext)//16
            k = 0
            for i in range(blocks):
                block = [chr(c) for c in plaintext[k:k+16]]
                if aesop == 'encrypt':
                    ciphertext = aes.encrypt(block)
                else:
                    ciphertext = aes.decrypt(block)

                self.dataModel.setData_s(u+k, u+k+16, ciphertext)

                k += 16
                #0123456789abcdef
                #00 11 22 33 44 55 66 77 bb 99 aa bb cc dd ee ff

        return True 
开发者ID:mtivadar,项目名称:qiew,代码行数:43,代码来源:enc_aes.py

示例5: use_slow_bundled_cryptography_module

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def use_slow_bundled_cryptography_module():
    import pyaes

    msg = "To make the program a *lot* faster, please install cryptography module: "
    msg += "pip install cryptography\n"
    print(msg, flush=True, file=sys.stderr)

    class BundledEncryptorAdapter:
        __slots__ = ('mode', )

        def __init__(self, mode):
            self.mode = mode

        def encrypt(self, data):
            encrypter = pyaes.Encrypter(self.mode, pyaes.PADDING_NONE)
            return encrypter.feed(data) + encrypter.feed()

        def decrypt(self, data):
            decrypter = pyaes.Decrypter(self.mode, pyaes.PADDING_NONE)
            return decrypter.feed(data) + decrypter.feed()

    def create_aes_ctr(key, iv):
        ctr = pyaes.Counter(iv)
        return pyaes.AESModeOfOperationCTR(key, ctr)

    def create_aes_cbc(key, iv):
        mode = pyaes.AESModeOfOperationCBC(key, iv)
        return BundledEncryptorAdapter(mode)
    return create_aes_ctr, create_aes_cbc 
开发者ID:alexbers,项目名称:mtprotoproxy,代码行数:31,代码来源:mtprotoproxy.py

示例6: aes_encrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def aes_encrypt(plaintext, key, iv):
    iv = iv.encode('utf-8')
    key = key.encode('utf-8')
    aes = pyaes.AESModeOfOperationCBC(key, iv=iv)
    ciphertext = aes.encrypt(plaintext)
    return base64.b64encode(ciphertext) 
开发者ID:lanmaster53,项目名称:recon-ng-marketplace,代码行数:8,代码来源:domain_creds.py

示例7: aes_decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def aes_decrypt(ciphertext, key, iv):
    ciphertext = base64.b64decode(ciphertext)
    iv = iv.encode('utf-8')
    key = key.encode('utf-8')
    aes = pyaes.AESModeOfOperationCBC(key, iv=iv)
    plaintext = aes.decrypt(ciphertext)
    return plaintext.decode("utf-8") 
开发者ID:lanmaster53,项目名称:recon-ng-marketplace,代码行数:9,代码来源:domain_creds.py

示例8: _aes_encrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def _aes_encrypt(text, sec_key):
    pad = 16 - len(text) % 16
    text = text + pad * chr(pad)
    aes = pyaes.AESModeOfOperationCBC(sec_key, iv='0102030405060708')
    ciphertext = ''
    while text != '':
        ciphertext += aes.encrypt(text[:16])
        text = text[16:]
    ciphertext = base64.b64encode(ciphertext)
    return ciphertext 
开发者ID:listen1,项目名称:listen1,代码行数:12,代码来源:netease.py

示例9: _encrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def _encrypt(password: str, data: bytes) -> Tuple[bytes, int, bytes, bytes]:
    """
    Encryption schema for private keys
    :param password: plaintext password to use for encryption
    :param data: plaintext data to encrypt
    :return: encrypted data, length of original data, initialisation vector for aes, password hashing salt
    """
    # Generate hash from password
    salt = os.urandom(16)
    hashed_pass = pbkdf2_hmac('sha256', password.encode(), salt, 2000000)

    # Random initialisation vector
    iv = os.urandom(16)

    # Encrypt data using AES
    aes = pyaes.AESModeOfOperationCBC(hashed_pass, iv=iv)

    # Pad data to multiple of 16
    n = len(data)
    if n % 16 != 0:
        data += b' ' * (16 - n % 16)

    encrypted = b''
    while len(data):
        encrypted += aes.encrypt(data[:16])
        data = data[16:]

    return encrypted, n, iv, salt 
开发者ID:fetchai,项目名称:ledger-api-py,代码行数:30,代码来源:entity.py

示例10: encrypt_pyaes

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def encrypt_pyaes(self, payload):
    aes = pyaes.AESModeOfOperationCBC(self.key, iv = bytes(self.iv))
    return "".join([aes.encrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)]) 
开发者ID:ralphm2004,项目名称:broadlink-thermostat,代码行数:5,代码来源:__init__.py

示例11: decrypt_pyaes

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def decrypt_pyaes(self, payload):
    aes = pyaes.AESModeOfOperationCBC(self.key, iv = bytes(self.iv))
    return "".join([aes.decrypt(bytes(payload[i:i+16])) for i in range(0, len(payload), 16)]) 
开发者ID:ralphm2004,项目名称:broadlink-thermostat,代码行数:5,代码来源:__init__.py

示例12: aes_encrypt_with_iv

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def aes_encrypt_with_iv(key, iv, data):
    aes_cbc = pyaes.AESModeOfOperationCBC(key, iv=iv)
    aes = pyaes.Encrypter(aes_cbc)
    e = aes.feed(data) + aes.feed()  # empty aes.feed() appends pkcs padding
    return e 
开发者ID:bitcoin-core,项目名称:HWI,代码行数:7,代码来源:digitalbitbox.py

示例13: aes_decrypt_with_iv

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def aes_decrypt_with_iv(key, iv, data):
    aes_cbc = pyaes.AESModeOfOperationCBC(key, iv=iv)
    aes = pyaes.Decrypter(aes_cbc)
    s = aes.feed(data) + aes.feed()  # empty aes.feed() strips pkcs padding
    return s 
开发者ID:bitcoin-core,项目名称:HWI,代码行数:7,代码来源:digitalbitbox.py

示例14: _encrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def _encrypt(self, data, iv):
        encrypter = pyaes.Encrypter(
                pyaes.AESModeOfOperationCBC(self._hash.hash, iv=native(iv)))
        enc_data = encrypter.feed(self.MAGIC_DETECT_ENC + data)
        enc_data += encrypter.feed()

        return enc_data 
开发者ID:JoinMarket-Org,项目名称:joinmarket-clientserver,代码行数:9,代码来源:storage.py

示例15: _decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import AESModeOfOperationCBC [as 别名]
def _decrypt(self, data, iv):
        decrypter = pyaes.Decrypter(
                pyaes.AESModeOfOperationCBC(self._hash.hash, iv=native(iv)))
        try:
            dec_data = decrypter.feed(data)
            dec_data += decrypter.feed()
        except ValueError:
            # in most "wrong password" cases the pkcs7 padding will be wrong
            raise StoragePasswordError("Wrong password.")

        if not dec_data.startswith(self.MAGIC_DETECT_ENC):
            raise StoragePasswordError("Wrong password.")
        return dec_data[len(self.MAGIC_DETECT_ENC):] 
开发者ID:JoinMarket-Org,项目名称:joinmarket-clientserver,代码行数:15,代码来源:storage.py


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