【问题标题】:Attempted to read or write protected memory. PKCS11Interop尝试读取或写入受保护的内存。 PKCS11互操作
【发布时间】:2017-04-12 00:33:31
【问题描述】:

我在突出显示的行中遇到访问冲突异常。

试图读取或写入受保护的内存。这通常表明其他内存已损坏。

我在 hsmlabel 上有证书。我正在将我的应用程序构建为 x64

public void getCertificateFromHSM(string certLabel) {

    List<ObjectAttribute> objectAttributes = new List<ObjectAttribute>();
    objectAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_CERTIFICATE));
    objectAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, certLabel));

    **session.FindObjectsInit(objectAttributes);** --Exception from here

    // Get search results
    List<ObjectHandle> foundObjects = session.FindObjects(2);

    // Terminate searching
    session.FindObjectsFinal();


    // Prepare list of empty attributes we want to read
    List<CKA> attributes = new List<CKA>();
    attributes.Add(CKA.CKA_LABEL);
    attributes.Add(CKA.CKA_VALUE);
}                                                                               

我从这行 session.FindObjectsInit(); 收到异常。我是pkcs11 的新手。

感谢您在这方面的任何帮助。

我还尝试通过传递 32 位 crypto.dll 将应用程序构建为 32 位,但在这种情况下,我在 PKCS11Interop Net.Pkcs11Interop.LowLevelAPI81.Delegates.InitializeWithGetF‌​unctionList(IntPtr libraryHandle) 的这一行中遇到异常,异常是

对于 UInt32,值太大或太小。溢出异常未处理。

【问题讨论】:

  • 我从这一行得到异常 (session.FindObjectsInit(); )。我是 pkcs11 的新手。感谢您在这方面的任何帮助。我还尝试通过传递 32 位加密 dll 将应用程序构建为 32 位,但在这种情况下,我从 PKCS11Interop Net.Pkcs11Interop.LowLevelAPI81.Delegates.InitializeWithGetFunctionList(IntPtr libraryHandle) 中的这一行得到异常,异常是 {"Value对于 UInt32 来说太大或太小。"} OverflowExcepiton 未处理。

标签: pkcs#11 pkcs11interop


【解决方案1】:

您似乎使用了错误的 HighLevelAPI 集。您需要使用 Net.Pkcs11Interop.HighLevelAPI 命名空间中的类,最后没有任何数字。

换句话说,您需要使用以下行

using Net.Pkcs11Interop.HighLevelAPI;

在您的代码中,而不是

using Net.Pkcs11Interop.HighLevelAPI81;

查看Pkcs11Interop library architecture了解更多信息,您还可以查看official code samples,它们也在使用Net.Pkcs11Interop.HighLevelAPI

【讨论】:

  • 很好的帮助。谢谢jariq :)
  • @SandeepSrinivasIndraganti 如果解决了您的问题,请将答案标记为已接受。您将获得徽章和其他 stackoverflow 好东西 :)
猜你喜欢
  • 2010-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-08
  • 2012-09-21
相关资源
最近更新 更多