コード例 #1
0
ファイル: test_common.py プロジェクト: nvv5/BaiduPCS-Py
def test_aes256cbccryptography_time():
    key = os.urandom(32)
    iv = os.urandom(16)
    c = AES256CBCCryptography(key, iv)
    buf = b"a" * 1024 * 1024 * 100
    start = time.time()
    enc = c.encrypt(buf)
    end = time.time()
    print("100M:", end - start, len(enc))
コード例 #2
0
ファイル: test_common.py プロジェクト: nvv5/BaiduPCS-Py
def test_aescryptography():
    key = os.urandom(32)
    iv = os.urandom(16)
    c = AES256CBCCryptography(key, iv)
    buf = b"a" * 16 * 2

    enc = c.encrypt(buf)
    print("enc:", enc, len(enc))
    enc += c._encryptor.finalize()

    dec = c.decrypt(enc[:16])
    print("dec:", dec, len(dec))
    dec += c.decrypt(enc[16:])
    print("dec:", dec, len(dec))
    dec += c._decryptor.finalize()
    assert buf == dec
コード例 #3
0
    def __init__(self, io: IO, encrypt_key: bytes, iv: bytes,
                 total_origin_len: int):
        encrypt_key = padding_key(encrypt_key, self.BLOCK_SIZE * 2)
        iv = padding_key(iv, self.BLOCK_SIZE)
        super().__init__(io, encrypt_key, iv, total_origin_len)

        self._crypto = AES256CBCCryptography(self._encrypt_key,
                                             self._nonce_or_iv)

        self._encrypted_io_offset = 0
        self._encrypted_io_len = padding_size(total_origin_len,
                                              self.BLOCK_SIZE)
        self._encrypted_data_padded = total_origin_len != self._encrypted_io_len

        self._encrypted_cache = bytearray()
        self._decrypted_cache = bytearray()
コード例 #4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self._crypto = AES256CBCCryptography(self._encrypt_key,
                                             self._nonce_or_iv)

        # The offset of encrypted origin content
        self._origin_io_offset = 0
        # Origin content cache
        self._origin_cache = bytearray()

        # Total length of final encrypted content
        self._encrypted_io_len = padding_size(self._io_len, self.BLOCK_SIZE)
        # Encrypted content cache
        self._encrypted_cache = bytearray()

        self._need_data_padded = self._total_origin_len != self._encrypted_io_len
コード例 #5
0
    def __init__(self, io: IO, encrypt_key: Any, iv: Any,
                 total_origin_len: int):
        encrypt_key = padding_key(encrypt_key, self.BLOCK_SIZE * 2)
        iv = padding_key(iv, self.BLOCK_SIZE)
        super().__init__(io, encrypt_key, iv, total_origin_len)

        self._crypto = AES256CBCCryptography(self._encrypt_key,
                                             self._nonce_or_iv)

        # The offset of encrypted origin content
        self._origin_io_offset = 0
        # Origin content cache
        self._origin_cache = bytearray()

        # Total length of final encrypted content
        self._encrypted_io_len = padding_size(self._io_len, self.BLOCK_SIZE)
        # Encrypted content cache
        self._encrypted_cache = bytearray()

        self._need_data_padded = self._total_origin_len != self._encrypted_io_len