コード例 #1
0
    def __init__(self, io: IO, encrypt_key: bytes, nonce: bytes,
                 total_origin_len: int):
        encrypt_key = padding_key(encrypt_key, self.BLOCK_SIZE * 2)
        nonce = padding_key(nonce, self.BLOCK_SIZE)
        super().__init__(io, encrypt_key, nonce, total_origin_len)

        self._crypto = ChaCha20Cryptography(self._encrypt_key,
                                            self._nonce_or_iv)
コード例 #2
0
ファイル: test_common.py プロジェクト: nvv5/BaiduPCS-Py
def test_chacha20cryptography():
    key = os.urandom(32)
    nonce = os.urandom(16)
    c = ChaCha20Cryptography(key, nonce)
    buf = os.urandom(100)
    enc = c.encrypt(buf)
    dec = c.decrypt(enc)
    assert buf == dec
コード例 #3
0
ファイル: test_common.py プロジェクト: nvv5/BaiduPCS-Py
def test_chacha20cryptography_time():
    key = os.urandom(32)
    nonce = os.urandom(16)
    c = ChaCha20Cryptography(key, nonce)
    buf = b"a" * 1024 * 1024 * 100
    start = time.time()
    c.encrypt(buf)
    end = time.time()
    print("100M:", end - start)
コード例 #4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._crypto = ChaCha20Cryptography(self._encrypt_key,
                                         self._nonce_or_iv)