add aes wrapper

This commit is contained in:
steinkirch.eth, phd 2023-07-06 15:56:47 -07:00
parent 991bd7d262
commit aa46218c3e
5 changed files with 821 additions and 571 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()