import types
from ctypes import *
SDK = cdll.LoadLibrary("/home/nxy/lib/libxxx.so")
def Sm4CbcEncrypt(source,key,iv):
v = c_int(0)
p_int = pointer(v)
p = create_string_buffer(len(source) + 64)
pconfig = addressof(p)
SDK.Sm4CbcEncrypt(source,len(source),pconfig,p_int,key,iv)
result = string_at(p,v)
p = None
return result
def Sm4CbcDecrypt(source,key,iv):
v = c_int(0)
p_int = pointer(v)
p = create_string_buffer(len(source) + 64)
pconfig = addressof(p)
SDK.Sm4CbcDecrypt(source,len(source),pconfig,p_int,key,iv)
result = string_at(p,v)
p = None
return result
en_data = Sm4CbcEncrypt("hello","1234567890abcdef","1234567890abcdef")
print("Sm4CbcEncrypt is over")
de_data = Sm4CbcDecrypt(en_data,"1234567890abcdef","1234567890abcdef")
print("Sm4CbcDecrypt is over")
print(de_data)
python调用c动态库
猜你喜欢
转载自blog.csdn.net/woailp___2005/article/details/106253801
今日推荐
周排行