如何将 C_FindObject 返回的 ulong Object_Handle 转换为 C# 中的 X509Certificate 对象。这是代码。
ulong[] foundObjectIds = new ulong[10];
foundObjectIds[0] = CK_INVALID_HANDLE;
success = PKCS11CsharpWrapper.C_FindObjects(session, foundObjectIds, Convert.ToUInt64(foundObjectIds.Length), ref foundObjectCount);
现在我必须将 foundObjectIds[0] 转换为 X509Certificate 对象。
我尝试了以下方法,但它对我不起作用。
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ulong)));
Marshal.StructureToPtr(foundObjectIds[0], ptr, false);
IntPtr[] arr = new IntPtr[2];
Marshal.Copy(ptr, arr, 0, 1);
X509Certificate2 cert= new X509Certificate2((IntPtr)foundObjectIds[0]);