gmssl version: v3.2.1(这里需要注意)
# -*- coding: utf-8 -*-
from gmssl import sm3, func
def str2byte(msg): # 字符串转换成byte数组
ml = len(msg)
msg_byte = []
msg_bytearray = msg.encode('utf-8')
for i in range(ml):
msg_byte.append(msg_bytearray[i])
return msg_byte
"""Use SM3 to calculate"""
def main():
while 1:
"Use SM3 to calculate"
print("输入待杂凑的内容:", end='')
data_str = str(input())
data_byte = str2byte(data_str)
hash_end = sm3.sm3_hash(func.bytes_to_list(data_byte))
print("输出结果是:", hash_end, "长度:<", len(hash_end), ">")
print("=======================================================")
print("\n")
if __name__ == '__main__':
main()
试试效果