add aes wrapper (#48)

This commit is contained in:
Dr. Marina Souza, PhD 2023-07-06 15:58:42 -07:00 committed by GitHub
parent 991bd7d262
commit abcc1d8aff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 821 additions and 574 deletions

View file

@ -0,0 +1,32 @@
# -*- encoding: utf-8 -*-
# math_utils.py
# This class implements math methods used by the other classes.
import base64
import hashlib
def str_to_bytes(data):
"""Convert string to bytes."""
utype = type(b''.decode('utf8'))
if isinstance(data, utype):
return data.encode('utf8')
return data
def b64encode(data: str) -> str:
"""Encode data to base64."""
return base64.b64encode(data).decode('utf-8')
def b64decode(data: str) -> str:
"""Decode base64 data."""
return base64.b64decode(data)
def hash256(data: str) -> str:
"""Hash data with SHA-256."""
return hashlib.sha256(str_to_bytes(data)).digest()