예제 #1
0
파일: helpers.py 프로젝트: emladen/dcs
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')
예제 #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')
예제 #3
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)
예제 #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.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)
예제 #5
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