예제 #1
0
 internal CspLegacy(String name, String type, ALG_IDCollection supportedAlgorithms)
 {
     Name = name;
     Type = type;
     if (supportedAlgorithms.Count > 0)
     {
         algs = new ALG_ID[supportedAlgorithms.Count];
         supportedAlgorithms.CopyTo(algs, 0);
     }
 }
예제 #2
0
파일: Csp.cs 프로젝트: nhtha/pkix.net
        static CspCollection m_enumprovs()
        {
            Hashtable     ProvTypes   = get_provtypes();
            StringBuilder pszProvName = new StringBuilder();
            CspCollection csps        = new CspCollection();

            UInt32 dwIndex     = 0;
            UInt32 pdwProvType = 0;
            UInt32 pcbProvName = 0;

            while (AdvAPI.CryptEnumProviders(dwIndex, 0, 0, ref pdwProvType, null, ref pcbProvName))
            {
                pszProvName.Length = (Int32)pcbProvName;
                // retrieve CSP
                if (!AdvAPI.CryptEnumProviders(dwIndex++, 0, 0, ref pdwProvType, pszProvName, ref pcbProvName))
                {
                    throw new Win32Exception(Error.InvalidDataException);
                }
                String name   = pszProvName.ToString();
                String pType  = (String)ProvTypes[pdwProvType];
                IntPtr phProv = IntPtr.Zero;
                // retrieve CSP context
                if (!AdvAPI.CryptAcquireContext(ref phProv, null, name, pdwProvType, Wincrypt.CRYPT_VERIFYCONTEXT))
                {
                    throw new Win32Exception(Error.InavlidHandleException);
                }
                Int32            pdwDataLen = 0;
                ALG_IDCollection algs       = new ALG_IDCollection();
                if (AdvAPI.CryptGetProvParam(phProv, 0x16, null, ref pdwDataLen, Wincrypt.CRYPT_FIRST))
                {
                    Byte[] pbData = new Byte[Marshal.SizeOf(typeof(Wincrypt.PROV_ENUMALGS_EX))];
                    while (AdvAPI.CryptGetProvParam(phProv, 0x16, pbData, ref pdwDataLen, Wincrypt.CRYPT_NEXT))
                    {
                        IntPtr ptr = Marshal.AllocHGlobal(pbData.Length);
                        Marshal.Copy(pbData, 0, ptr, pbData.Length);
                        Wincrypt.PROV_ENUMALGS_EX AlgStructure =
                            (Wincrypt.PROV_ENUMALGS_EX)Marshal.PtrToStructure(ptr, typeof(Wincrypt.PROV_ENUMALGS_EX));
                        Marshal.FreeHGlobal(ptr);
                        ALG_ID alg = get_algparams(AlgStructure);
                        algs.Add(alg);
                    }
                    csps.Add(new CspLegacy(name, pType, algs));
                }
                else
                {
                    csps.Add(new CspLegacy(name, pType, algs));
                }
                AdvAPI.CryptReleaseContext(phProv, 0);
            }
            return(csps);
        }
예제 #3
0
 internal ALG_IDCollectionEnumerator(ALG_IDCollection entries)
 {
     m_entries = entries;
     m_current = -1;
 }