|
@@ -1,26 +1,20 @@
|
|
import ctypes
|
|
import ctypes
|
|
|
|
|
|
-# 加载共享库
|
|
|
|
-lib = ctypes.CDLL('libgmsign.so')
|
|
|
|
-
|
|
|
|
-# 定义函数的参数和返回类型
|
|
|
|
-# 签名函数签名如下:
|
|
|
|
-# int sign(char *key_value, char *hash_value, char *public_key)
|
|
|
|
-lib.sign.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
|
|
|
|
-lib.sign.restype = ctypes.c_int
|
|
|
|
-
|
|
|
|
-# 验签函数签名如下:
|
|
|
|
-# int sign_verify(char *content, char *sign_value, char *public_key)
|
|
|
|
-lib.sign_verify.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
|
|
|
|
-lib.sign_verify.restype = ctypes.c_int
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def get_sign(raw_data: str) -> (str, str):
|
|
def get_sign(raw_data: str) -> (str, str):
|
|
"""
|
|
"""
|
|
获取签名值
|
|
获取签名值
|
|
:param raw_data: 原文字符串
|
|
:param raw_data: 原文字符串
|
|
:return: tuple(str,str):(签名值base64字符串,公钥base64字符串)
|
|
:return: tuple(str,str):(签名值base64字符串,公钥base64字符串)
|
|
"""
|
|
"""
|
|
|
|
+ # 加载共享库
|
|
|
|
+ lib = ctypes.CDLL('libgmsign.so')
|
|
|
|
+
|
|
|
|
+ # 定义函数的参数和返回类型
|
|
|
|
+ # 签名函数签名如下:
|
|
|
|
+ # int sign(char *key_value, char *hash_value, char *public_key)
|
|
|
|
+ lib.sign.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
|
|
|
|
+ lib.sign.restype = ctypes.c_int
|
|
|
|
+
|
|
key_value = raw_data.replace(" ", "").encode('utf-8')
|
|
key_value = raw_data.replace(" ", "").encode('utf-8')
|
|
hash_value = ctypes.create_string_buffer(256) # 设置签名值输出缓冲区大小为 256 字节
|
|
hash_value = ctypes.create_string_buffer(256) # 设置签名值输出缓冲区大小为 256 字节
|
|
public_key = ctypes.create_string_buffer(256) # 设置公钥输出缓冲区大小为 256 字节
|
|
public_key = ctypes.create_string_buffer(256) # 设置公钥输出缓冲区大小为 256 字节
|
|
@@ -41,6 +35,13 @@ def verify_sign(raw_data: str, sign_data: str, public_key: str) -> bool:
|
|
:param public_key: 公钥base64字符串
|
|
:param public_key: 公钥base64字符串
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
|
|
+ # 加载共享库
|
|
|
|
+ lib = ctypes.CDLL('libgmsign.so')
|
|
|
|
+ # 验签函数签名如下:
|
|
|
|
+ # int sign_verify(char *content, char *sign_value, char *public_key)
|
|
|
|
+ lib.sign_verify.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
|
|
|
|
+ lib.sign_verify.restype = ctypes.c_int
|
|
|
|
+
|
|
content = raw_data.replace(" ", "").encode('utf-8')
|
|
content = raw_data.replace(" ", "").encode('utf-8')
|
|
sign_value = sign_data.encode('utf-8')
|
|
sign_value = sign_data.encode('utf-8')
|
|
public_key = public_key.encode('utf-8')
|
|
public_key = public_key.encode('utf-8')
|