Пример #1
0
def encode_message(request: Request):
    return templates.TemplateResponse('form.html',
                                      context={
                                          'request': request,
                                          'path': '/symmetric/encode',
                                          'sym_key': check_key()
                                      })
Пример #2
0
def set_key(request: Request):

    return templates.TemplateResponse('set_key.html',
                                      context={
                                          'request': request,
                                          'sym_key': check_key()
                                      })
Пример #3
0
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'
                                      })
Пример #4
0
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()
                                      })
Пример #5
0
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'
                                      })
Пример #6
0
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'
                                      })
Пример #7
0
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'
                                      })
Пример #8
0
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'
                                      })
Пример #9
0
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'
                                      })
Пример #10
0
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
        })
Пример #11
0
def asym_decode_message(request: Request):
    return templates.TemplateResponse('form.html',
                                      context={
                                          'request': request,
                                          'path': '/asymmetric/decode'
                                      })
Пример #12
0
def verify_message(request: Request):
    return templates.TemplateResponse('form_verify.html',
                                      context={'request': request})
Пример #13
0
def sign_message(request: Request):
    return templates.TemplateResponse('form.html',
                                      context={
                                          'request': request,
                                          'path': '/asymmetric/sign'
                                      })
Пример #14
0
def set_keys(request: Request):
    return templates.TemplateResponse('asym_form.html',
                                      context={'request': request})