mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-18 06:30:23 -04:00
add aes wrapper (#48)
This commit is contained in:
parent
991bd7d262
commit
abcc1d8aff
6 changed files with 821 additions and 574 deletions
32
web3-toolkit/libraries/math_utils.py
Normal file
32
web3-toolkit/libraries/math_utils.py
Normal 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()
|
Loading…
Add table
Add a link
Reference in a new issue