/// <summary> /// Initializes the hash key storage by executing the key location strategy. /// </summary> /// <param name="keyLocation">The name of the hash key location.</param> /// <param name="keyLocationStrategy">The hash key location strategy.</param> /// <param name="keyStorage">The hash key storage.</param> protected void ResolveKeyStorage( string keyLocation, IKeyLocationStrategy keyLocationStrategy, IKeyStorageAsync keyStorage) { try { if (keyLocationStrategy == null) { keyLocationStrategy = ServiceLocatorWrapper.Default.GetInstance <IKeyLocationStrategy>(); } } catch (ActivationException) { keyLocationStrategy = new KeyLocationStrategy(); } KeyLocation = keyLocationStrategy.GetKeyLocation(keyLocation); try { if (keyStorage == null) { keyStorage = ServiceLocatorWrapper.Default.GetInstance <IKeyStorageAsync>(); } } catch (ActivationException) { keyStorage = new KeyFile(); } KeyStorage = keyStorage; }
/// <summary> /// Initializes a new instance of the <see cref="ProtectedKeyCipher"/> class. /// </summary> /// <param name="symmetricAlgorithmName"> /// The name of the symmetric algorithm implementation. You can use any of the constants from <see cref="Algorithms.Symmetric"/> or /// <see langword="null"/>, empty or whitespace characters only - these will default to <see cref="Algorithms.Symmetric.Default"/>. /// Also a string instance with name "DefaultSymmetricEncryption" can be defined in a Common Service Locator compatible dependency injection container. /// </param> /// <param name="symmetricKeyLocation"> /// Seeding name of store location name of the encrypted symmetric key (e.g. relative or absolute path). /// Can be <see langword="null"/>, empty or whitespace characters only. /// The parameter will be passed to the <paramref name="symmetricKeyLocationStrategy"/> to determine the final store location name path (e.g. relative or absolute path). /// </param> /// <param name="symmetricKeyLocationStrategy"> /// Object which implements the strategy for determining the store location name (e.g. path and filename) of the encrypted symmetric key. /// If <see langword="null"/> it defaults to a new instance of the class <see cref="KeyLocationStrategy"/>. /// </param> /// <param name="keyStorage"> /// Object which implements the storing and retrieving of the the encrypted symmetric key to and from the store with the determined location name. /// If <see langword="null"/> it defaults to a new instance of the class <see cref="KeyFile"/>. /// </param> public ProtectedKeyXmlCipher( string symmetricAlgorithmName = null, string symmetricKeyLocation = null, IKeyLocationStrategy symmetricKeyLocationStrategy = null, IKeyStorageAsync keyStorage = null) : this(symmetricAlgorithmName) { ResolveKeyStorage(symmetricKeyLocation, symmetricKeyLocationStrategy, keyStorage); }
/// <summary> /// Initializes a new instance of the <see cref="EncryptedNewKeyCipher" /> class. /// </summary> /// <param name="certificate"> /// The certificate containing the public and optionally the private key for encryption and decryption of the symmetric key. /// If the parameter is <see langword="null"/> the method will try to resolve its value from the Common Service Locator with resolve name "EncryptingCertificate". /// </param> /// <param name="symmetricAlgorithmName"> /// The name of the symmetric algorithm implementation. You can use any of the constants from <see cref="Algorithms.Symmetric" /> or /// <see langword="null" />, empty or whitespace characters only - these will default to <see cref="Algorithms.Symmetric.Default" />. /// Also a string instance with name "DefaultSymmetricEncryption" can be defined in a Common Service Locator compatible dependency injection container. /// </param> /// <param name="symmetricKeyLocation"> /// Seeding name of store location name of the encrypted symmetric key (e.g. relative or absolute path). /// Can be <see langword="null"/>, empty or whitespace characters only. /// The parameter will be passed to the <paramref name="symmetricKeyLocationStrategy"/> to determine the final store location name path (e.g. relative or absolute path). /// </param> /// <param name="symmetricKeyLocationStrategy"> /// Object which implements the strategy for determining the store location name (e.g. path and filename) of the encrypted symmetric key. /// If <see langword="null"/> it defaults to a new instance of the class <see cref="KeyLocationStrategy"/>. /// </param> /// <param name="keyStorage"> /// Object which implements the storing and retrieving of the the encrypted symmetric key to and from the store with the determined location name. /// If <see langword="null"/> it defaults to a new instance of the class <see cref="KeyFile"/>. /// </param> /// <exception cref="System.ArgumentNullException"> /// Thrown when the <paramref name="certificate" /> is <see langword="null" /> and could not be resolved from the Common Service Locator. /// </exception> public EncryptedKeyCipher( X509Certificate2 certificate = null, string symmetricAlgorithmName = null, string symmetricKeyLocation = null, IKeyLocationStrategy symmetricKeyLocationStrategy = null, IKeyStorageAsync keyStorage = null) : this(symmetricAlgorithmName, certificate) { ResolveKeyStorage(symmetricKeyLocation, symmetricKeyLocationStrategy, keyStorage); }
public KeyedHasher( X509Certificate2 certificate, string hashAlgorithmName = null, string keyLocation = null, IKeyLocationStrategy keyLocationStrategy = null, IKeyStorageAsync keyStorage = null) { var hashAlgorithmFactory = ServiceLocatorWrapper.Default.GetInstance <IHashAlgorithmFactory>(Algorithms.KeyedHash.ResolveName); hashAlgorithmFactory.Initialize(hashAlgorithmName); _hashAlgorithm = (KeyedHashAlgorithm)hashAlgorithmFactory.Create(); ResolveKeyStorage(keyLocation, keyLocationStrategy, keyStorage); InitializeAsymmetricKeys(certificate); }