Ejemplo n.º 1
0
def decrypt(key, encoded):
    key = key.encode('ascii')
    padded_key = key.ljust(KEY_SIZE, b'\0')

    ciphertext = base64.b64decode(encoded.encode('ascii'))

    sg = pprp.data_source_gen(ciphertext, block_size=BLOCK_SIZE)
    dg = pprp.rjindael_decrypt_gen(padded_key, sg, block_size=BLOCK_SIZE)

    return pprp.decrypt_sink(dg).decode('utf-8')
Ejemplo n.º 2
0
    def decryptRjindael(self, key, data):

        key_size = 16
        block_size = 32
        padded_key = key.ljust(key_size, b'\0')

        ciphertext = base64.b64decode(data)

        sg = pprp.data_source_gen(ciphertext, block_size=block_size)
        dg = pprp.rjindael_decrypt_gen(padded_key, sg, block_size=block_size)

        return pprp.decrypt_sink(dg).decode('utf-8')
Ejemplo n.º 3
0
def encrypt(key, plaintext):
    key = key.encode('ascii')
    plaintext = plaintext.encode('utf-8')
    padded_key = key.ljust(KEY_SIZE, b'\0')

    sg = pprp.data_source_gen(plaintext, block_size=BLOCK_SIZE)
    eg = pprp.rjindael_encrypt_gen(padded_key, sg, block_size=BLOCK_SIZE)

    ciphertext = pprp.encrypt_sink(eg)

    encoded = base64.b64encode(ciphertext)

    return encoded.decode('ascii')
Ejemplo n.º 4
0
    def test_full(self):
        passphrase = 'password'.encode('ASCII')
        salt = 'salt'.encode('ASCII')

        key_size = 32
        data = "this is a test" * 100
        data_bytes = data.encode('ASCII')

        key = pprp.pbkdf2(passphrase, salt, key_size)

        # Create a source from available data.
        sg = pprp.data_source_gen(data_bytes)

        # Feed the source into the encryptor.
        eg = pprp.rijndael_encrypt_gen(key, sg)

        # Feed the encryptor into the decryptor.
        dg = pprp.rijndael_decrypt_gen(key, eg)

        # Sink the output into an IO-stream.
        decrypted = pprp.decrypt_sink(dg)

        self.assertEquals(data_bytes, decrypted)
Ejemplo n.º 5
0
    def test_full(self):
        passphrase = 'password'.encode('ASCII')
        salt = 'salt'.encode('ASCII')

        key_size = 32
        data = "this is a test" * 100
        data_bytes = data.encode('ASCII')

        key = pprp.pbkdf2(passphrase, salt, key_size)

        # Create a source from available data.
        sg = pprp.data_source_gen(data_bytes)

        # Feed the source into the encryptor.
        eg = pprp.rjindael_encrypt_gen(key, sg)

        # Feed the encryptor into the decryptor.
        dg = pprp.rjindael_decrypt_gen(key, eg)

        # Sink the output into an IO-stream.
        decrypted = pprp.decrypt_sink(dg)

        self.assertEquals(data_bytes, decrypted)
Ejemplo n.º 6
0
    logger.addHandler(ch)


_configure_logging()


def trans(text):
    return text.encode('ASCII') if sys.version_info[0] >= 3 else text


passphrase = trans('password')
salt = trans('salt')
key_size = 32
data = ("this is a test" * 100).encode('ASCII')

key = pprp.pbkdf2(passphrase, salt, key_size)

# Create a source from available data.
sg = pprp.data_source_gen(data)

# Feed the source into the encryptor.
eg = pprp.rjindael_encrypt_gen(key, sg)

# Feed the encryptor into the decryptor.
dg = pprp.rjindael_decrypt_gen(key, eg)

# Sink the output into an IO-stream.
decrypted = pprp.decrypt_sink(dg)

assert data == decrypted
Ejemplo n.º 7
0
    logger.addHandler(ch)


_configure_logging()


def trans(text):
    return text.encode('ASCII') if sys.version_info[0] >= 3 else text


passphrase = trans('password')
salt = trans('salt')
key_size = 32
data = ("this is a test" * 100).encode('ASCII')

key = pprp.pbkdf2(passphrase, salt, key_size)

# Encrypt.

sg = pprp.data_source_gen(data)
eg = pprp.rjindael_encrypt_gen(key, sg)
encrypted = pprp.encrypt_sink(eg)

# Decrypt.

sg = pprp.data_source_gen(encrypted)
dg = pprp.rjindael_decrypt_gen(key, sg)
decrypted = pprp.decrypt_sink(dg)

assert data == decrypted