예제 #1
0
        private static void ConfigureCryptography()
        {
            XDocument document;

            using (var reader = ResourceUtils.GetXmlResource("OpenGost.Security.Cryptography.Crypto.config"))
                document = XDocument.Load(reader, LoadOptions.None);

            var cryptographySettings = document
                                       .Element(XName.Get("configuration"))?
                                       .Element(XName.Get("mscorlib"))?
                                       .Element(XName.Get("cryptographySettings"));

            if (cryptographySettings == null)
            {
                return;
            }

            var cryptoNameMapping = cryptographySettings.Element(XName.Get("cryptoNameMapping"));

            if (cryptoNameMapping != null)
            {
                ConfigureCryptoNameMapping(cryptoNameMapping);
            }

            var oidMap = cryptographySettings.Element(XName.Get("oidMap"));

            if (oidMap != null)
            {
                ConfigureOidMap(oidMap);
            }
        }
        private static XmlSchemaSet LoadECDsaXmlSchemaSet()
        {
            var schemas = new XmlSchemaSet();

            using (var stream = ResourceUtils.GetXmlResource("OpenGost.Security.Cryptography.ECDsa.xsd"))
                schemas.Add(XmlSchema.Read(stream, null) !);
            schemas.Compile();
            return(schemas);
        }
예제 #3
0
        private static void ConfigureCryptography()
        {
            string mscorlibVersion = typeof(CryptoConfig).Assembly.GetName().Version.ToString();

            using (XmlReader reader = ResourceUtils.GetXmlResource("OpenGost.Security.Cryptography.Tests.Crypto.config"))
            {
                var               document         = new XPathDocument(reader);
                XPathNavigator    navigator        = document.CreateNavigator();
                XPathNodeIterator mscorlibIterator = navigator.Select("configuration/mscorlib");
                XPathNavigator    mscorlib         = null;
                while (mscorlibIterator.MoveNext())
                {
                    bool              versionSpecificMscorlib = false;
                    XPathNavigator    current = mscorlibIterator.Current;
                    XPathNodeIterator versionAttributeIterator = current.Select("@version");
                    while (versionAttributeIterator.MoveNext())
                    {
                        versionSpecificMscorlib = true;

                        if (mscorlibVersion == versionAttributeIterator.Current.Value)
                        {
                            mscorlib = current;
                            break;
                        }
                    }

                    if (!versionSpecificMscorlib)
                    {
                        mscorlib = current;
                    }

                    if (mscorlib != null)
                    {
                        break;
                    }
                }

                if (mscorlib == null)
                {
                    return;
                }

                XPathNavigator cryptographySettings = mscorlib.SelectSingleNode("cryptographySettings");

                if (cryptographySettings == null)
                {
                    return;
                }

                XPathNavigator cryptoNameMapping = cryptographySettings.SelectSingleNode("cryptoNameMapping");
                if (cryptoNameMapping != null)
                {
                    ConfigureCryptoNameMapping(cryptoNameMapping);
                }

                XPathNavigator oidMap = cryptographySettings.SelectSingleNode("oidMap");
                if (oidMap != null)
                {
                    ConfigureOidMap(oidMap);
                }
            }
        }