程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python calls go dynamic library

編輯:Python

because python Of AES Encrypted results and Go The encryption result of is always wrong , Finally, development can only provide one Go The secret library of , use python To call , Ensure that the encryption result is the same .

Go The development method of generating dynamic library knows , Don't write ,windows The dynamic library is .dll,Linux yes .so, No matter what kind of ,python It's called in the same way

Only record here python Call mode :

Go What the dynamic library receives and returns is C_type Format , therefore python The call also needs to be converted to the corresponding C_type Format , This table can be referenced for conversion

if __name__ == "__main__":
lib = cdll.LoadLibrary("C:\\Users\\ws\\Downloads\\skm-share-codec.dll")
lib.aes_encrypt.argtypes = [ctypes.c_char_p, ctypes.c_int] # Parameter format conversion
lib.aes_encrypt.restype = ctypes.c_char_p # Return value format conversion
token_dict = {
"inviteeType": 1,
"invitee": "[email protected]",
"resourceType": 4,
"resourceId": 433,
"shareType": 7,
"expireAt": 1666253258
}
data = json.dumps(token_dict) # The developer informs that the received serial number cha Array
charArray = bytes(data.encode('utf-8')) # c_type Char Array correspondence python Of bytes
aa = lib.aes_encrypt(charArray, len(charArray))
print(type(aa))
print(aa)
print(aa.decode("utf-8").split(","))

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved