Commit 71925e57 authored by Daniel Hofmann's avatar Daniel Hofmann
Browse files

Initial py interop

parent 63fed8f7
......@@ -15,6 +15,11 @@ Dependencies:
- Interoperability, local environment, e.g. for python:
virtualenv .env
source .env/bin/activate
pip install -r interop/py/requirements.txt
Installation of the Server
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division, with_statement # welcome to the future
import argparse
import logging
import base64
from Crypto.Cipher import AES
def aes_config():
parser = argparse.ArgumentParser(description='AES (in CBC mode) language interop tester')
parser.add_argument('-i', '--iv', dest='iv', default='{0}'.format(AES.block_size * '0'),
help='initialization vector, has to be of size {0} bytes'.format(AES.block_size))
parser.add_argument('-k', '--key', dest='key', default='{0}'.format(AES.key_size[0] * '0'),
help='key, size has to be {0} bytes'.format(" or ".join(map(lambda i: str(i), AES.key_size))))
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='increased output verbosity')
parser.add_argument('-p', '--plaintext', dest='plaintext', required=True,
help='plaintext to encrypt')
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
return {'iv': args.iv, 'key': args.key, 'in': args.plaintext}
def aes_cipher(key, iv):
assert(len(iv) == AES.block_size), 'iv size mismatch'
assert(len(key) in AES.key_size), 'key size mismatch'
return, AES.MODE_CBC, iv)
def main():
cfg = aes_config()'{0}'.format(cfg))
aes = aes_cipher(cfg['key'], cfg['iv'])
next_mult = lambda x, n: n + (x - n % x) if n % x else n
fill = (next_mult(AES.block_size, len(cfg['in'])) - len(cfg['in'])) * '0'
pad = cfg['in'] + fill
enc = cfg['iv'] + aes.encrypt(pad)
b64 = base64.b64encode(enc)'{0}'.format({'padded': pad, 'base64': b64}))
if __name__ == '__main__':
# vim: set tabstop=4 shiftwidth=4 expandtab:
filename = *.py,*.cfg
max-line-length = 120
show-source = True
show-pep8 = False
max-complexity = 10
exclude = ./env/*,./setup.cfg
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment