/// <summary> /// Loads all Cryptoki certificates for the specified certificate store (if supported). /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="storeName">The certificate store moniker.</param> /// <returns>The loaded cryptoki certificate object array</returns> public static CryptokiCertificate[] LoadCertificates(Session session, string storeName) { CryptokiCertificate[] certs; CryptokiAttribute[] attribs = new CryptokiAttribute[] { new CryptokiAttribute(CryptokiAttribute.CryptokiType.Class, Utility.ConvertToBytes((int)CryptokiClass.CERTIFICATE)), new CryptokiAttribute(CryptokiAttribute.CryptokiType.Label, UTF8Encoding.UTF8.GetBytes(storeName)), }; FindObjectEnum objEnum = new FindObjectEnum(session, attribs); if (objEnum.Count == 0) { certs = new CryptokiCertificate[0]; } else { Array ar = objEnum.GetNext(objEnum.Count); certs = ar as CryptokiCertificate[]; } objEnum.Close(); return(certs); }
/// <summary> /// Initializes a new instance of the X509Certificate2 class from a byte array /// </summary> /// <param name="session">Cryptoki session for which this certificate will be created</param> /// <param name="data">Data bytes for the certificate (PEM, DER, P12, etc.)</param> /// <param name="password">Password for decrypting the certificate data (optional)</param> public X509Certificate2(Session session, byte[] data, string password="") { if (data == null || data.Length == 0) throw new ArgumentException(); m_cert = CryptokiCertificate.LoadCertificate(session, data, password); Init(); }
/// <summary> /// Creates a Cryptoki certificate object with the specified attribute array template and session context. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="template">The attribute template that defines the certificate properties.</param> /// <returns>The created cryptoki certificate object</returns> public static CryptokiCertificate CreateCertificate(Session session, CryptokiAttribute[] template) { CryptokiCertificate ret = CreateObject(session, template) as CryptokiCertificate; ret.m_propertyBag = new Hashtable(); session.AddSessionObject(ret); return(ret); }
internal X509Certificate2(CryptokiCertificate cert) { m_cert = cert; Init(); }
/// <summary> /// Initializes a new instance of the X509Certificate2 class from a Cryptoki attribute array /// </summary> /// <param name="session"></param> /// <param name="template"></param> public X509Certificate2(Session session, CryptokiAttribute[] template) { m_cert = CryptokiCertificate.CreateCertificate(session, template); Init(); }
/// <summary> /// Loads all Cryptoki certificates for the specified certificate store (if supported). /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="storeName">The certificate store moniker.</param> /// <returns>The loaded cryptoki certificate object array</returns> public static CryptokiCertificate[] LoadCertificates(Session session, string storeName) { CryptokiCertificate[] certs; CryptokiAttribute[] attribs = new CryptokiAttribute[] { new CryptokiAttribute(CryptokiAttribute.CryptokiType.Class, Utility.ConvertToBytes((int)CryptokiClass.CERTIFICATE)), new CryptokiAttribute(CryptokiAttribute.CryptokiType.Label, UTF8Encoding.UTF8.GetBytes(storeName)), }; FindObjectEnum objEnum = new FindObjectEnum(session, attribs); if (objEnum.Count == 0) { certs = new CryptokiCertificate[0]; } else { Array ar = objEnum.GetNext(objEnum.Count); certs = ar as CryptokiCertificate[]; } objEnum.Close(); return certs; }