Beispiel #1
0
        internal static string FindOidInfo(uint keyType, string keyValue, System.Security.Cryptography.OidGroup oidGroup)
        {
            if (keyValue == null)
            {
                throw new ArgumentNullException("keyValue");
            }
            if (keyValue.Length == 0)
            {
                return(null);
            }
            SafeLocalAllocHandle invalidHandle = SafeLocalAllocHandle.InvalidHandle;

            switch (keyType)
            {
            case 1:
                invalidHandle = StringToAnsiPtr(keyValue);
                break;

            case 2:
                invalidHandle = StringToUniPtr(keyValue);
                break;
            }
            CAPIBase.CRYPT_OID_INFO crypt_oid_info = CAPI.CryptFindOIDInfo(keyType, invalidHandle, oidGroup);
            if ((crypt_oid_info.pszOID == null) && (oidGroup != System.Security.Cryptography.OidGroup.AllGroups))
            {
                crypt_oid_info = CAPI.CryptFindOIDInfo(keyType, invalidHandle, System.Security.Cryptography.OidGroup.AllGroups);
            }
            if (keyType == 1)
            {
                return(crypt_oid_info.pwszName);
            }
            return(crypt_oid_info.pszOID);
        }
Beispiel #2
0
        internal static string FindOidInfo(uint keyType, string keyValue, System.Security.Cryptography.OidGroup oidGroup)
        {
            if (keyValue == null)
            {
                throw new ArgumentNullException("keyValue");
            }
            if (keyValue.Length == 0)
            {
                return(null);
            }

#if MONO
            switch (keyType)
            {
            case CAPI.CRYPT_OID_INFO_OID_KEY:
                return(CAPI.CryptFindOIDInfoNameFromKey(keyValue, oidGroup));

            case CAPI.CRYPT_OID_INFO_NAME_KEY:
                return(CAPI.CryptFindOIDInfoKeyFromName(keyValue, oidGroup));

            default:
                throw new NotImplementedException(keyType.ToString());
            }
#else
            SafeLocalAllocHandle pvKey = SafeLocalAllocHandle.InvalidHandle;

            try {
                switch (keyType)
                {
                case CAPI.CRYPT_OID_INFO_OID_KEY:
                    pvKey = StringToAnsiPtr(keyValue);
                    break;

                case CAPI.CRYPT_OID_INFO_NAME_KEY:
                    pvKey = StringToUniPtr(keyValue);
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }

                CAPI.CRYPT_OID_INFO pOidInfo = CAPI.CryptFindOIDInfo(keyType, pvKey, oidGroup);


                if (keyType == CAPI.CRYPT_OID_INFO_OID_KEY)
                {
                    return(pOidInfo.pwszName);
                }
                else
                {
                    return(pOidInfo.pszOID);
                }
            }
            finally {
                pvKey.Dispose();
            }
#endif
        }
Beispiel #3
0
        // Try to find OID info within a specific group, and if that doesn't work fall back to all
        // groups for compatibility with previous frameworks
        internal static string FindOidInfoWithFallback(uint key, string value, System.Security.Cryptography.OidGroup group)
        {
            string info = FindOidInfo(key, value, group);

            // If we couldn't find it in the requested group, then try again in all groups
            if (info == null && group != System.Security.Cryptography.OidGroup.All)
            {
                info = FindOidInfo(key, value, System.Security.Cryptography.OidGroup.All);
            }

            return(info);
        }