![](/img/trans.png)
[英]Value was either too large or too small for a UInt32 Error on iOS WKWebView & Uno 2.4
[英]Softhsm2 with pkcs11interop error. Value was either too large or too small for a UInt32
我有以下代码通过pkcs11interop库进行softhsm2测试
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI;
using Net.Pkcs11Interop.HighLevelAPI80;
using System;
using System.Collections.Generic;
namespace ExportTest
{
public class Softhsmtest
{
public static Pkcs11InteropFactories Factories = new Pkcs11InteropFactories();
public static void Test()
{
using (Pkcs11 pkcs11 = new Pkcs11(Factories, @"C:\SoftHSM2\lib\softhsm2.dll",AppType.MultiThreaded))
{
ISlot slot = pkcs11.GetSlotList(SlotsType.WithTokenPresent)[0];
using (ISession session = slot.OpenSession(SessionType.ReadWrite))
{
session.Login(CKU.CKU_USER, "1111");
session.Logout();
}
}
}
}
}
我得到的错误Stacktrace是
at System.Convert.ToUInt32(UInt64 value)
at Net.Pkcs11Interop.Common.ConvertUtils.UInt64ToCKR(UInt64 value)
at Net.Pkcs11Interop.LowLevelAPI80.Delegates.InitializeWithGetFunctionList(IntPtr libraryHandle)
at Net.Pkcs11Interop.LowLevelAPI80.Delegates..ctor(IntPtr libraryHandle, Boolean useGetFunctionList)
at Net.Pkcs11Interop.LowLevelAPI80.Pkcs11..ctor(String libraryPath)
at Net.Pkcs11Interop.HighLevelAPI80.Pkcs11..ctor(Pkcs11InteropFactories factories, String libraryPath, AppType appType)
at ExportTest.Softhsmtest.Test() in C:\Users\kashahid\Downloads
\\ Pkcs11Interop-master \\ Pkcs11Interop-master \\ src \\ PkcsTestWindowsApp \\ Class1.cs:C:\\ Users \\ kashahid \\ Downloads \\ Pkcs11Interop-master \\ Pkcs11Interop-master \\中PkcsTestWindowsApp.Form1.button1_click(Object sender,EventArgs e)的行15 src \\ PkcsTestWindowsApp \\ Form1.cs:第27行,位于System.Windows.Forms.Control.OnClick(EventArgs e),位于System.Windows.Forms.Button.OnClick(EventArgs e),位于System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)(位于System.Windows.Forms.Control.WmMouseUp(Message&m,MouseButtons button,Int32 clicks)位于System.Windows.Forms.Control.WndProc(Message&m),位于System.Windows.Forms.ButtonBase.WndProc(Message&m)在System.Windows.Forms.Controls.ControlNativeWindow.OnMessage(Message&m)在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)在System.Windows.Forms.Button.WndProc(Message&m) .Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW( MSG和msg)在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32原因,Int32 pvLoopData)在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因,位于System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32原因,ApplicationContext上下文)位于System.Windows.Forms.Application.Run(表单mainForm),位于C:\\ Users中的PkcsTestWindowsApp.Program.Main() \\ kashahid \\ Downloads \\ Pkcs11Interop-master \\ Pkcs11Interop-master \\ src \\ PkcsTestWindowsApp \\ Program.cs:line 19
我在那里看到两个问题:
您正在使用Pkcs11Interop(主分支)的当前开发版本,该版本包含一些API重大更改,并且将在变为稳定版本之前更改LOT。
您直接从Net.Pkcs11Interop.HighLevelAPI80
命名空间引用类型,这些类型应该仅在Unix系统上使用。
解决方案:
您应该使用当前稳定版本-Pkcs11Interop 4.1.0-结合以下代码:
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI;
namespace ExportTest
{
public class Softhsmtest
{
public static void Test()
{
using (Pkcs11 pkcs11 = new Pkcs11(@"C:\SoftHSM2\lib\softhsm2.dll", AppType.MultiThreaded))
{
Slot slot = pkcs11.GetSlotList(SlotsType.WithTokenPresent)[0];
using (Session session = slot.OpenSession(SessionType.ReadWrite))
{
session.Login(CKU.CKU_USER, "1111");
session.Logout();
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.