I'm using ncryptoki for sign with HSM on multithread operation (with parallel for in .net linq). In order to avoid parallel operation errors, i have use thread locked while accessing NCryptoki sources.
Code thrown exception "Error: Error n. 6 StackTrace: at Cryptware.NCryptoki.Certificate.get_CertificateValue()" while executing SignOperationHelper.ecertificate() method.
public class SignOperationHelper { private static object lockObject = new object(); static public ECertificate ecertificate() { lock (lockObject) return new SomeInstance(n.certificateX509.CertificateValue); } }
public class SignOperationHelper
{
private static object lockObject = new object();
static public ECertificate ecertificate() { lock (lockObject) return new SomeInstance(n.certificateX509.CertificateValue); }
}