完整代码
https://gitee.com/ihan1001
https://github.com/ihan1001
重点:时间戳,MD5哈希,SHA256哈希,base64一种用64个字符表示任意二进制数据的方法,ECC椭圆曲线算法

import timetime.time()

datetime.now().strftime("%Y-%m-%d %H:%M:%S")

import hashlibm=hashlib.md5()m.update('使用md5加密的数据'.encode('utf-8'))print(m.hexdigest())

s = hashlib.sha256()h = hashlib.sha256()s.update('i'.encode('utf-8'))s.update('h'.encode('utf-8'))s.update('a'.encode('utf-8'))s.update('h'.encode('utf-8'))print(s.hexdigest())h.update('ihan'.encode('utf-8'))print(h.hexdigest())

#base64 一种用64个字符表示任意二进制数据的方法import base64data = '你好,ihan'#加密result = base64.b64encode(data.encode('utf-8'))print(result)

#解码text = base64.b64decode(result)print(text.decode('utf-8'))

pip install ecdsa

from ecdsa import SigningKey,SECP256k1#椭圆曲线算法#生成一对私钥和公钥#私钥对字符串签名,公钥验证#生成私钥sk = SigningKey.generate(curve = SECP256k1)sk

#生成公钥vk = sk.get_verifying_key()vk
#生成签名signature = sk.sign("ihan".encode("utf-8"))
#验证签名vk.verify(signature,"ihan".encode("utf-8"))