public XElement WriteSection(Type providerType) { Ensure.ArgumentNotNull(providerType, "providerType"); if (!typeof(ICryptoProvider).IsAssignableFrom(providerType)) { throw new ConfigException("The supplied type must implement DeepConfig.Cryptography.ICryptoProvider.", ConfigErrorCode.InvalidConfigType); } var mangledTypeName = new CryptoCryptoProvider().Encrypt(providerType.AssemblyQualifiedName); return new XElement( ConfigElement.CryptoSettingNode, new XAttribute(ConfigElement.SectionTypeAttribute, mangledTypeName)); }
public ICryptoProvider ReadSection(XElement section) { if (section == null) { return null; } string mangledTypeName = section.GetAttributeValue(ConfigElement.SectionTypeAttribute); if (mangledTypeName == null) { return null; } string typeName = new CryptoCryptoProvider().Decrypt(mangledTypeName); var result = ConfigHelper.CreateInstance(typeName, true) as ICryptoProvider; if (result == null) { throw new ConfigException(Msg.Text("Unable to resolve or create Cryptoprovider ({0}).", typeName), ConfigErrorCode.CryptographyProviderCreationFailed); } return result; }