Esempio n. 1
0
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
Esempio n. 2
0
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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._crypto = SimpleCryptography(self._encrypt_key +
                                       self._nonce_or_iv)
Esempio n. 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)