def encode_message(request: Request): return templates.TemplateResponse('form.html', context={ 'request': request, 'path': '/symmetric/encode', 'sym_key': check_key() })
def set_key(request: Request): return templates.TemplateResponse('set_key.html', context={ 'request': request, 'sym_key': check_key() })
def random_key(request: Request): key = sym.create_key() return templates.TemplateResponse('random_key.html', context={ 'request': request, 'key': key, 'sym_key': check_key(), 'mode': 'sym' })
def set_key(request: Request, key: str = Form(...)): if not sym.set_key(key): raise HTTPException(status_code=422, detail='check data') return templates.TemplateResponse('set_key.html', context={ 'request': request, 'key': sym.key, 'sym_key': check_key() })
def get_ssh_keys(request: Request): temp = asym.create_ssh_keys() return templates.TemplateResponse('random_key.html', context={ 'request': request, 'private': temp['private'], 'public': temp['public'], 'mode': 'asym' })
def encode_message_post(request: Request, message: str = Form(...)): encrypted_message = sym.encode_message(message) if encrypted_message == message: raise HTTPException(status_code=422, detail='check data') return templates.TemplateResponse('sym_message.html', context={ 'message': encrypted_message, 'request': request, 'sym_key': check_key(), 'templ': 'encode' })
def sign_message(request: Request, message: str = Form(...)): signature = asym.sign_message(message) if message == signature: raise HTTPException(status_code=422, detail='check data') return templates.TemplateResponse('sign.html', context={ 'request': request, 'sign': signature, 'mode': 'sign' })
def asym_decode_message(request: Request, message: str = Form(...)): decrypted_message = asym.decode_message(message) if message == decrypted_message: raise HTTPException(status_code=422, detail='Incorrect data provided') return templates.TemplateResponse('sym_message.html', context={ 'message': decrypted_message, 'request': request, 'templ': 'decode' })
def verify_message(request: Request, message: str = Form(...), signature: str = Form(...)): if not asym.verify_message(message, signature): raise HTTPException(status_code=422, detail='check data') return templates.TemplateResponse('sign.html', context={ 'request': request, 'signature': 'verified', 'sign': signature, 'mode': 'verify' })
def home(request: Request): if 'public' in asym.keys.keys(): public = asym.keys['public'] private = asym.keys['private'] else: public = '' private = '' return templates.TemplateResponse( "index.html", { "request": request, 'sym_key': check_key(), 'public': public, 'private': private })
def asym_decode_message(request: Request): return templates.TemplateResponse('form.html', context={ 'request': request, 'path': '/asymmetric/decode' })
def verify_message(request: Request): return templates.TemplateResponse('form_verify.html', context={'request': request})
def sign_message(request: Request): return templates.TemplateResponse('form.html', context={ 'request': request, 'path': '/asymmetric/sign' })
def set_keys(request: Request): return templates.TemplateResponse('asym_form.html', context={'request': request})