/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> public ObjectAttribute(CKA type, CKK value) { if (Platform.UnmanagedLongSize == 4) { if (Platform.StructPackingSize == 0) { _objectAttribute40 = new HighLevelAPI40.ObjectAttribute(type, value); } else { _objectAttribute41 = new HighLevelAPI41.ObjectAttribute(type, value); } } else { if (Platform.StructPackingSize == 0) { _objectAttribute80 = new HighLevelAPI80.ObjectAttribute(type, value); } else { _objectAttribute81 = new HighLevelAPI81.ObjectAttribute(type, value); } } }
public void GenerateAsymmetricKeyPair(CKK keyType, List <ObjectAttribute> privateKeyObjectAttributes, List <ObjectAttribute> publicKeyObjectAttributes) { if (privateKeyObjectAttributes == null) { throw new ArgumentNullException("privateKeyObjectAttributes"); } if (publicKeyObjectAttributes == null) { throw new ArgumentNullException("publicKeyObjectAttributes"); } if (!Pkcs11Admin.Instance.Config.PrivateKeyAttributes.TypeSpecificAttributes.ContainsKey((ulong)keyType)) { throw new Exception("Unsupported key type"); } CKM?mechanismType = Pkcs11Admin.Instance.Config.PrivateKeyAttributes.TypeSpecificAttributes[(ulong)keyType].KeyGenerationMechanism; if (mechanismType == null) { throw new Exception("Key generation mechanism not specified"); } ObjectHandle privateKeyHandle = null; ObjectHandle publicKeyHandle = null; using (Session session = _slot.OpenSession(SessionType.ReadWrite)) using (Mechanism mechanism = new Mechanism(mechanismType.Value)) session.GenerateKeyPair(mechanism, publicKeyObjectAttributes, privateKeyObjectAttributes, out publicKeyHandle, out privateKeyHandle); }
private Dictionary <CKM, List <CKK> > GetKnownKeyGenerationMechanisms(TypeAttributes typeSpecificAttributes) { Dictionary <CKM, List <CKK> > knownMechanisms = new Dictionary <CKM, List <CKK> >(); foreach (KeyValuePair <ulong, ClassAttributes> typeAttributes in typeSpecificAttributes) { CKK keyType = (CKK)typeAttributes.Key; CKM?mechanism = typeAttributes.Value.KeyGenerationMechanism; if (mechanism != null) { if (!knownMechanisms.ContainsKey(mechanism.Value)) { knownMechanisms.Add(mechanism.Value, new List <CKK>() { keyType }); } else { knownMechanisms[mechanism.Value].Add(keyType); } } } return(knownMechanisms); }
public void GenerateSymmetricKey(CKK keyType, List <ObjectAttribute> objectAttributes) { if (objectAttributes == null) { throw new ArgumentNullException("objectAttributes"); } if (!Pkcs11Admin.Instance.Config.SecretKeyAttributes.TypeSpecificAttributes.ContainsKey((ulong)keyType)) { throw new Exception("Unsupported key type"); } CKM?mechanismType = Pkcs11Admin.Instance.Config.SecretKeyAttributes.TypeSpecificAttributes[(ulong)keyType].KeyGenerationMechanism; if (mechanismType == null) { throw new Exception("Key generation mechanism not specified"); } using (Session session = _slot.OpenSession(SessionType.ReadWrite)) using (Mechanism mechanism = new Mechanism(mechanismType.Value)) session.GenerateKey(mechanism, objectAttributes); }
// Checks if KeyType of Cert is of the given type public bool CheckKeyType(Slot slot, CKK keyType) { if (this.CkaId.Length == 0) { return(false); } bool result; using (Session session = slot.OpenSession(SessionType.ReadOnly)) { List <ObjectAttribute> searchTemplate = new List <ObjectAttribute>(); searchTemplate.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_PUBLIC_KEY)); searchTemplate.Add(new ObjectAttribute(CKA.CKA_ID, this.CkaId)); searchTemplate.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, keyType)); List <ObjectHandle> foundObjects = session.FindAllObjects(searchTemplate); session.FindObjectsInit(searchTemplate); result = session.FindObjects(1).Count != 0; session.FindObjectsFinal(); return(result); } }
public ComboBoxKeyTypeItem(CKK keyType, Kinds kind) { this.KeyType = keyType; this.Kind = kind; }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of given type with CKK value</returns> public static CK_ATTRIBUTE CreateAttribute(CKA type, CKK value) { return(CreateAttribute(ConvertUtils.UInt32FromCKA(type), ConvertUtils.UInt32FromCKK(value))); }
/// <summary> /// Converts CKK to UInt32 /// </summary> /// <param name="value">CKK that should be converted</param> /// <returns>UInt32 with value from CKK</returns> public static UInt32 UInt32FromCKK(CKK value) { return(Convert.ToUInt32(value)); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> public ObjectAttribute(CKA type, CKK value) { _ckAttribute = CkaUtils.CreateAttribute(type, value); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of given type with CKK value</returns> public static CK_ATTRIBUTE CreateAttribute(CKA type, CKK value) { return(CreateAttribute(Convert.ToUInt64((uint)type), Convert.ToUInt64((uint)value))); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of given type with CKK value</returns> public static CK_ATTRIBUTE CreateAttribute(CKA type, CKK value) { return CreateAttribute(Convert.ToUInt64((uint)type), Convert.ToUInt64((uint)value)); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of given type with CKK value</returns> public static CK_ATTRIBUTE CreateAttribute(CKA type, CKK value) { return(CreateAttribute((uint)type, (uint)value)); }
/// <summary> /// Converts CKK to UInt64 /// </summary> /// <param name="value">CKK that should be converted</param> /// <returns>UInt64 with value from CKK</returns> public static UInt64 UInt64FromCKK(CKK value) { return(Convert.ToUInt64(value)); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of given type with CKK value</returns> public static CK_ATTRIBUTE CreateAttribute(CKA type, CKK value) { return CreateAttribute((uint)type, (uint)value); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of cryptoki object</returns> public IObjectAttribute Create(CKA type, CKK value) { return(_factory.Create(type, value)); }
/// <summary> /// Converts CKK to NativeULong /// </summary> /// <param name="value">CKK that should be converted</param> /// <returns>NativeULong with value from CKK</returns> public static NativeULong ConvertFromCKK(CKK value) { return(Convert.ToUInt64(value)); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> public ObjectAttribute(CKA type, CKK value) { if (Platform.UnmanagedLongSize == 4) { if (Platform.StructPackingSize == 0) _objectAttribute40 = new HighLevelAPI40.ObjectAttribute(type, value); else _objectAttribute41 = new HighLevelAPI41.ObjectAttribute(type, value); } else { if (Platform.StructPackingSize == 0) _objectAttribute80 = new HighLevelAPI80.ObjectAttribute(type, value); else _objectAttribute81 = new HighLevelAPI81.ObjectAttribute(type, value); } }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of given type with CKK value</returns> public static CK_ATTRIBUTE CreateAttribute(CKA type, CKK value) { return(CreateAttribute(NativeLongUtils.ConvertFromCKA(type), NativeLongUtils.ConvertFromCKK(value))); }
/// <summary> /// Creates attribute of given type with CKK value /// </summary> /// <param name="type">Attribute type</param> /// <param name="value">Attribute value</param> /// <returns>Attribute of cryptoki object</returns> public IObjectAttribute CreateObjectAttribute(CKA type, CKK value) { return(new ObjectAttribute(type, value)); }
public KeyTypeAttribute(CKK keyType) : base((uint)CKA.KEY_TYPE) { KeyType = keyType; }