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


Python pyaes.Encrypter方法代碼示例

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


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

示例1: encrypt_aes_cbc

# 需要導入模塊: import pyaes [as 別名]
# 或者: from pyaes import Encrypter [as 別名]
def encrypt_aes_cbc(key, plaintext, iv=None):
        """Return AES CBC encrypted string.

        Args:
            key (bytes): The encryption key.
            plaintext (str|bytes): The text to encrypt.
            iv (bytes, optional): The CBC initial vector.

        Returns:
            bytes: The encoded string.
        """
        iv = iv or b'\0' * 16

        # ensure key is bytes
        if isinstance(key, str):
            key = key.encode()

        # ensure plaintext is bytes
        if isinstance(plaintext, str):
            plaintext = plaintext.encode()

        # ensure iv is bytes
        if isinstance(iv, str):
            iv = iv.encode()

        aes_cbc_encrypt = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(key, iv=iv))
        encrypted = aes_cbc_encrypt.feed(plaintext)
        encrypted += aes_cbc_encrypt.feed()
        return encrypted 
開發者ID:ThreatConnect-Inc,項目名稱:tcex,代碼行數:31,代碼來源:utils.py

示例2: use_slow_bundled_cryptography_module

# 需要導入模塊: import pyaes [as 別名]
# 或者: from pyaes import Encrypter [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

示例3: TestIssue15

# 需要導入模塊: import pyaes [as 別名]
# 或者: from pyaes import Encrypter [as 別名]
def TestIssue15():
    print('Issue #15')

    key = b"abcdefghijklmnop"
    iv = b"0123456789012345"
    encrypter = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(key, iv))

    plaintext = b"Hello World!!!!!"

    ciphertext = to_bufferable('')

    ciphertext += encrypter.feed(plaintext)
    ciphertext += encrypter.feed('')
    ciphertext += encrypter.feed(plaintext)
    ciphertext += encrypter.feed(None)
    expected = b'(Ob\xe5\xae"\xdc\xb0\x84\xc5\x04\x04GQ\xd8.\x0e4\xd2b\xc1\x15\xe5\x11M\xfc\x9a\xd2\xd5\xc8xP\x00[\xd57\x92\x01\xbb\xc42\x18\xbc\xbf\x1ay\x19P'

    decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv))

    output = to_bufferable('')

    output += decrypter.feed('')
    output += decrypter.feed(ciphertext)
    output += decrypter.feed('')
    output += decrypter.feed(None)

    print("  passed=%(passed)s" % dict(passed = (ciphertext == expected and output == (plaintext + plaintext)))) 
開發者ID:ricmoo,項目名稱:pyaes,代碼行數:29,代碼來源:test-blockfeeder.py

示例4: aes_encrypt_with_iv

# 需要導入模塊: import pyaes [as 別名]
# 或者: from pyaes import Encrypter [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

示例5: _encrypt

# 需要導入模塊: import pyaes [as 別名]
# 或者: from pyaes import Encrypter [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

示例6: encrypt_py

# 需要導入模塊: import pyaes [as 別名]
# 或者: from pyaes import Encrypter [as 別名]
def encrypt_py(plain_text, key):
    if plain_text:
        try:
            scraper_key = hashlib.sha256(key).digest()
            IV = '\0' * 16
            decrypter = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(scraper_key, IV))
            cipher_text = decrypter.feed(plain_text)
            cipher_text += decrypter.feed()
        except Exception as e:
            log_utils.log_warning('Exception during Py Encrypt: %s' % (e))
            cipher_text = ''
    else:
        cipher_text = ''

    return cipher_text 
開發者ID:mrknow,項目名稱:filmkodi,代碼行數:17,代碼來源:common.py

示例7: aes_cbc_encrypt

# 需要導入模塊: import pyaes [as 別名]
# 或者: from pyaes import Encrypter [as 別名]
def aes_cbc_encrypt(key: bytes, iv: bytes, data: str) -> bytes:
    encrypter = Encrypter(AESModeOfOperationCBC(key, iv))
    encrypted = encrypter.feed(data) + encrypter.feed()
    return encrypted 
開發者ID:mkb79,項目名稱:Audible,代碼行數:6,代碼來源:aescipher.py


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