/// <summary> /// Gets the property value given the specified property name. /// </summary> /// <param name="propName">The property name</param> /// <returns>The property value object</returns> public object GetProperty(CertificateProperty propName) { object retVal = null; if (m_propertyBag == null) m_propertyBag = new Hashtable(); if (m_propertyBag.Contains(propName)) { retVal = m_propertyBag[propName] as Byte[]; } else { byte[] propValue = new byte[2048]; byte[] propLen = new byte[4]; CryptokiAttribute[] props = new CryptokiAttribute[] { new CryptokiAttribute((CryptokiAttribute.CryptokiType)propName, propValue), new CryptokiAttribute( CryptokiAttribute.CryptokiType.ValueLen, propLen ), }; if(GetAttributeValues(ref props)) { switch(propName) { case CertificateProperty.KeyType: retVal = (KeyType)Utility.ConvertToInt32(propValue); break; case CertificateProperty.SignatureAlgorithm: retVal = (MechanismType)Utility.ConvertToInt32(propValue); break; case CertificateProperty.Issuer: case CertificateProperty.Subject: retVal = new string(UTF8Encoding.UTF8.GetChars(propValue)); break; case CertificateProperty.SerialNumber: case CertificateProperty.RawBytes: { int len = Utility.ConvertToInt32(propLen); if (len < propValue.Length) { byte[] tmp = new byte[len]; Array.Copy(propValue, tmp, len); propValue = tmp; } } retVal = propValue; break; case CertificateProperty.EffectiveDate: case CertificateProperty.ExpirationDate: DATE_TIME_INFO dti = new DATE_TIME_INFO(propValue); retVal = new DateTime(dti.year, dti.month, dti.day, dti.hour, dti.minute, dti.second, dti.msec); break; } } if (retVal != null) { m_propertyBag[propName] = retVal; } } return retVal; }
/// <summary> /// Gets the property value given the specified property name. /// </summary> /// <param name="propName">The property name</param> /// <returns>The property value object</returns> public object GetProperty(CertificateProperty propName) { object retVal = null; if (m_propertyBag == null) { m_propertyBag = new Hashtable(); } if (m_propertyBag.Contains(propName)) { retVal = m_propertyBag[propName] as Byte[]; } else { byte[] propValue = new byte[2048]; byte[] propLen = new byte[4]; CryptokiAttribute[] props = new CryptokiAttribute[] { new CryptokiAttribute((CryptokiAttribute.CryptokiType)propName, propValue), new CryptokiAttribute(CryptokiAttribute.CryptokiType.ValueLen, propLen), }; if (GetAttributeValues(ref props)) { switch (propName) { case CertificateProperty.KeyType: retVal = (KeyType)Utility.ConvertToInt32(propValue); break; case CertificateProperty.SignatureAlgorithm: retVal = (MechanismType)Utility.ConvertToInt32(propValue); break; case CertificateProperty.Issuer: case CertificateProperty.Subject: retVal = new string(UTF8Encoding.UTF8.GetChars(propValue)); break; case CertificateProperty.SerialNumber: case CertificateProperty.RawBytes: { int len = Utility.ConvertToInt32(propLen); if (len < propValue.Length) { byte[] tmp = new byte[len]; Array.Copy(propValue, tmp, len); propValue = tmp; } } retVal = propValue; break; case CertificateProperty.EffectiveDate: case CertificateProperty.ExpirationDate: DATE_TIME_INFO dti = new DATE_TIME_INFO(propValue); retVal = new DateTime(dti.year, dti.month, dti.day, dti.hour, dti.minute, dti.second, dti.msec); break; } } if (retVal != null) { m_propertyBag[propName] = retVal; } } return(retVal); }