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(","))