コード例 #1
0
ファイル: test_common.py プロジェクト: nvv5/BaiduPCS-Py
def test_simplecryptography():
    key = os.urandom(32)
    c = SimpleCryptography(key)
    buf = os.urandom(100)
    enc = c.encrypt(buf)
    dec = c.decrypt(enc)
    assert buf == dec
コード例 #2
0
ファイル: test_common.py プロジェクト: nvv5/BaiduPCS-Py
def test_simplecryptography_time():
    key = os.urandom(32)
    c = SimpleCryptography(key)
    buf = b"a" * 1024 * 1024 * 100
    start = time.time()
    c.encrypt(buf)
    end = time.time()
    print("100M:", end - start)
コード例 #3
0
    def __init__(self, io: IO, encrypt_key: Any, nonce_or_iv: Any,
                 total_origin_len: int):
        encrypt_key = padding_key(encrypt_key, self.BLOCK_SIZE * 2)
        nonce_or_iv = padding_key(nonce_or_iv, self.BLOCK_SIZE)
        super().__init__(io, encrypt_key, nonce_or_iv, total_origin_len)

        self._crypto = SimpleCryptography(self._encrypt_key)
コード例 #4
0
class SimpleDecryptIO(DecryptIO):
    def __init__(self, io: IO, encrypt_key: Any, total_origin_len: int):
        encrypt_key = padding_key(encrypt_key, 32)
        super().__init__(io, encrypt_key, None, total_origin_len)

        self._crypto = SimpleCryptography(self._encrypt_key)

    def read(self, size: int = -1) -> Optional[bytes]:
        data = self._io.read(size)
        if not data:
            return b""
        self._offset += len(data)
        return self._crypto.decrypt(data)

    def seekable(self) -> bool:
        return True
コード例 #5
0
class SimpleDecryptIO(DecryptIO):
    def __init__(self, io: IO, encrypt_key: bytes, nonce: bytes,
                 total_origin_len: int):
        super().__init__(io, encrypt_key, nonce, total_origin_len)

        self._crypto = SimpleCryptography(self._encrypt_key +
                                          self._nonce_or_iv)

    def read(self, size: int = -1) -> Optional[bytes]:
        data = self._io.read(size)
        if not data:
            return b""
        self._offset += len(data)
        return self._crypto.decrypt(data)

    def seekable(self) -> bool:
        return True
コード例 #6
0
    def __init__(self, io: IO, encrypt_key: bytes, nonce: bytes,
                 total_origin_len: int):
        super().__init__(io, encrypt_key, nonce, total_origin_len)

        self._crypto = SimpleCryptography(self._encrypt_key +
                                          self._nonce_or_iv)
コード例 #7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._crypto = SimpleCryptography(self._encrypt_key +
                                       self._nonce_or_iv)
コード例 #8
0
    def __init__(self, io: IO, encrypt_key: Any, total_origin_len: int):
        encrypt_key = padding_key(encrypt_key, 32)
        super().__init__(io, encrypt_key, None, total_origin_len)

        self._crypto = SimpleCryptography(self._encrypt_key)