/// <summary> /// Creates a object in the given Cryptoki session context with specified object atrributes. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="template">The object attribute template.</param> /// <returns>The cryptoki object created.</returns> public static CryptokiObject CreateObject(Session session, CryptokiAttribute[] template) { CryptokiObject ret = CreateObjectInternal(session, template); session.AddSessionObject(ret); return ret; }
/// <summary> /// Creates a object in the given Cryptoki session context with specified object atrributes. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="template">The object attribute template.</param> /// <returns>The cryptoki object created.</returns> public static CryptokiObject CreateObject(Session session, CryptokiAttribute[] template) { CryptokiObject ret = CreateObjectInternal(session, template); session.AddSessionObject(ret); return(ret); }
/// <summary> /// Creates a session container object with the specified session context. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="ownsSession">Determines if the container disposes the session object.</param> protected SessionContainer(Session session, bool ownsSession) { m_ownsSession = ownsSession; m_session = session; if (!ownsSession) { session.AddSessionObject(this); } }
/// <summary> /// Creates a session container object with the specified session context. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="ownsSession">Determines if the container disposes the session object.</param> protected SessionContainer(Session session, bool ownsSession) { m_ownsSession = ownsSession; m_session = session; if (!ownsSession) { session.AddSessionObject(this); } }
/// <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); }
/// <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; }
/// <summary> /// Imports a key of specifed type given the raw key bytes and key class. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="keyData">The raw key data bytes.</param> /// <param name="keyClass">The class of key represented by the raw bytes.</param> /// <param name="keyType">The type of key represented by the raw bytes.</param> /// <param name="canBeExported">true if the key can be exported, false other wise.</param> /// <returns>The key created from the specified bytes.</returns> public static CryptoKey ImportKey(Session session, byte[] keyData, KeyClass keyClass, KeyType keyType, bool canBeExported) { CryptokiAttribute[] keyImport = new CryptokiAttribute[] { new CryptokiAttribute(CryptokiAttribute.CryptokiType.Class , Utility.ConvertToBytes((int)keyClass)), new CryptokiAttribute(CryptokiAttribute.CryptokiType.KeyType, Utility.ConvertToBytes((int)keyType)), new CryptokiAttribute(CryptokiAttribute.CryptokiType.Value, keyData), new CryptokiAttribute(CryptokiAttribute.CryptokiType.Extractable, Utility.ConvertToBytes(canBeExported ? 1 : 0)), }; CryptoKey ret = LoadKey(session, keyImport); session.AddSessionObject(ret); return ret; }
/// <summary> /// Unwraps the specified key data with the given wrapping key and mechanism. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="mechanism">The key wrapping mechanism or algorithm.</param> /// <param name="wrappingKey">The key that will be used to unwrap the specifed keyData.</param> /// <param name="keyData">The encrypted key data.</param> /// <param name="keyTemplate">The key attribute template.</param> /// <returns>The unwrapped key object.</returns> public static CryptoKey UnwrapKey(Session session, Mechanism mechanism, CryptoKey wrappingKey, byte[] keyData, CryptokiAttribute[] keyTemplate) { CryptoKey ret = UnwrapKeyInternal(session, mechanism, wrappingKey, keyData, keyTemplate); if (ret != null) { session.AddSessionObject(ret); } return ret; }
/// <summary> /// Generates a new CryptoKey object that represents a public/private key pair. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="mechanism">The key algorithm and parameters.</param> /// <param name="publicKeyTemplate">The public key attribute template.</param> /// <param name="privateKeyTemplate">The private key attribute template.</param> /// <returns></returns> public static CryptoKey GenerateKeyPair(Session session, Mechanism mechanism, CryptokiAttribute[] publicKeyTemplate, CryptokiAttribute[] privateKeyTemplate) { CryptoKey ret = GenerateKeyPairInternal(session, mechanism, publicKeyTemplate, privateKeyTemplate); session.AddSessionObject(ret); return ret; }
/// <summary> /// Generates a new CryptoKey within the specified session context with the specified key mechanism and key template. /// </summary> /// <param name="session">The Cryptoki session context.</param> /// <param name="mechanism">The key algorithm and parameters.</param> /// <param name="template">The key attribute template that defines the resulting key's properties.</param> /// <returns></returns> public static CryptoKey GenerateKey(Session session, Mechanism mechanism, CryptokiAttribute[] template) { CryptoKey ret = GenerateKeyInternal(session, mechanism, template); session.AddSessionObject(ret); return ret; }