Exemple #1
0
        private static CRYPT_OID_INFO FindOidInfo(OidKeyType keyType, string key, OidGroup group)
        {
            IntPtr intPtr = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            CRYPT_OID_INFO result;

            try
            {
                if (keyType == OidKeyType.Oid)
                {
                    intPtr = Marshal.StringToCoTaskMemAnsi(key);
                }
                else
                {
                    intPtr = Marshal.StringToCoTaskMemUni(key);
                }
                if (!X509Utils.OidGroupWillNotUseActiveDirectory(group))
                {
                    OidGroup dwGroupId = group | OidGroup.DisableSearchDS;
                    IntPtr   intPtr2   = X509Utils.CryptFindOIDInfo(keyType, intPtr, dwGroupId);
                    if (intPtr2 != IntPtr.Zero)
                    {
                        return((CRYPT_OID_INFO)Marshal.PtrToStructure(intPtr2, typeof(CRYPT_OID_INFO)));
                    }
                }
                IntPtr intPtr3 = X509Utils.CryptFindOIDInfo(keyType, intPtr, group);
                if (intPtr3 != IntPtr.Zero)
                {
                    result = (CRYPT_OID_INFO)Marshal.PtrToStructure(intPtr3, typeof(CRYPT_OID_INFO));
                }
                else
                {
                    if (group != OidGroup.AllGroups)
                    {
                        IntPtr intPtr4 = X509Utils.CryptFindOIDInfo(keyType, intPtr, OidGroup.AllGroups);
                        if (intPtr4 != IntPtr.Zero)
                        {
                            return((CRYPT_OID_INFO)Marshal.PtrToStructure(intPtr4, typeof(CRYPT_OID_INFO)));
                        }
                    }
                    result = default(CRYPT_OID_INFO);
                }
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(intPtr);
                }
            }
            return(result);
        }
Exemple #2
0
        private static CRYPT_OID_INFO FindOidInfo(OidKeyType keyType, string key, OidGroup group)
        {
            IntPtr num = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                num = keyType != OidKeyType.Oid ? Marshal.StringToCoTaskMemUni(key) : Marshal.StringToCoTaskMemAnsi(key);
                if (!X509Utils.OidGroupWillNotUseActiveDirectory(group))
                {
                    OidGroup dwGroupId = group | OidGroup.DisableSearchDS;
                    IntPtr   oidInfo   = X509Utils.CryptFindOIDInfo(keyType, num, dwGroupId);
                    if (oidInfo != IntPtr.Zero)
                    {
                        return((CRYPT_OID_INFO)Marshal.PtrToStructure(oidInfo, typeof(CRYPT_OID_INFO)));
                    }
                }
                IntPtr oidInfo1 = X509Utils.CryptFindOIDInfo(keyType, num, group);
                if (oidInfo1 != IntPtr.Zero)
                {
                    return((CRYPT_OID_INFO)Marshal.PtrToStructure(oidInfo1, typeof(CRYPT_OID_INFO)));
                }
                if (group != OidGroup.AllGroups && X509Utils.CryptFindOIDInfo(keyType, num, OidGroup.AllGroups) != IntPtr.Zero)
                {
                    return((CRYPT_OID_INFO)Marshal.PtrToStructure(oidInfo1, typeof(CRYPT_OID_INFO)));
                }
                return(new CRYPT_OID_INFO());
            }
            finally
            {
                if (num != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(num);
                }
            }
        }