Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
 /// <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,
     IKeyStorageTasks keyStorage)
 {
     KeyLocation = Resolver.GetInstanceOrDefault(keyLocationStrategy).GetKeyLocation(keyLocation);
     KeyStorage  = Resolver.GetInstanceOrDefault(keyStorage);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:vm.Aspects.Security.Cryptography.Ciphers.ProtectedData.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"/>.
 /// </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="DefaultServices.KeyFileLocationStrategy"/>.
 /// </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="DefaultServices.KeyFileStorage"/>.
 /// </param>
 public ProtectedKeyXmlCipher(
     string symmetricAlgorithmName = null,
     string symmetricKeyLocation   = null,
     IKeyLocationStrategy symmetricKeyLocationStrategy = null,
     IKeyStorageTasks keyStorage = null)
     : this(symmetricAlgorithmName)
 {
     ResolveKeyStorage(symmetricKeyLocation, symmetricKeyLocationStrategy, keyStorage);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes the key storage by executing the key location strategy.
 /// </summary>
 /// <param name="symmetricKeyLocation">
 /// The name of the symmetric key location which must be relevant to the chosen <see cref="IKeyLocationStrategy"/>.
 /// </param>
 /// <param name="symmetricKeyLocationStrategy">
 /// Translates the <paramref name="symmetricKeyLocation"/> to the chosen concrete key store relevant specific key location.
 /// </param>
 /// <param name="keyStorage">
 /// The key storage.
 /// </param>
 protected void ResolveKeyStorage(
     string symmetricKeyLocation,
     IKeyLocationStrategy symmetricKeyLocationStrategy,
     IKeyStorageTasks keyStorage)
 {
     KeyLocation = DefaultServices.Resolver.GetInstanceOrDefault(symmetricKeyLocationStrategy)
                   .GetKeyLocation(symmetricKeyLocation);
     KeyStorage = DefaultServices.Resolver.GetInstanceOrDefault(keyStorage);
 }
Exemplo n.º 5
0
 /// <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 &quot;EncryptingCertificate&quot;.
 /// </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 &quot;DefaultSymmetricEncryption&quot; 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);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProtectedKeyCipher" /> class.
 /// </summary>
 /// <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="DefaultServices.KeyFileLocationStrategy" />.
 /// Alternatively an implementation type can be registered in a common service locator compatible DI container.</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="DefaultServices.KeyFileStorage" />.
 /// Alternatively an implementation type can be registered in a common service locator compatible DI container.
 /// </param>
 /// <param name="symmetricAlgorithmName">
 /// The name of the symmetric algorithm implementation. You can use any of the constants from <see cref="Algorithms.Symmetric" /> or even
 /// <see langword="null" />, empty or whitespace characters only - these will default to <see cref="Algorithms.Symmetric.Default" />.
 /// </param>
 /// <param name="symmetricAlgorithmFactory">
 /// The symmetric algorithm factory. If <see langword="null" /> the constructor will create an instance of the <see cref="DefaultServices.SymmetricAlgorithmFactory" />,
 /// which uses the <see cref="SymmetricAlgorithm.Create(string)" /> method from the .NET library.
 /// </param>
 public ProtectedKeyCipher(
     string symmetricKeyLocation = null,
     IKeyLocationStrategy symmetricKeyLocationStrategy = null,
     IKeyStorageTasks keyStorage   = null,
     string symmetricAlgorithmName = Algorithms.Symmetric.Default,
     ISymmetricAlgorithmFactory symmetricAlgorithmFactory = null)
     : base(symmetricAlgorithmName, symmetricAlgorithmFactory)
 {
     ResolveKeyStorage(symmetricKeyLocation, symmetricKeyLocationStrategy, keyStorage);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EncryptedNewKeyXmlCipher" /> class.
 /// </summary>
 /// <param name="certificate">
 /// The certificate containing the public and optionally the private key for encryption and decryption of the symmetric key.
 /// </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" />.
 /// </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="DefaultServices.KeyFileLocationStrategy"/>.
 /// </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="DefaultServices.KeyFileStorage"/>.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// Thrown when the <paramref name="certificate" /> is <see langword="null" />.
 /// </exception>
 public EncryptedKeyXmlCipher(
     X509Certificate2 certificate  = null,
     string symmetricAlgorithmName = null,
     string symmetricKeyLocation   = null,
     IKeyLocationStrategy symmetricKeyLocationStrategy = null,
     IKeyStorageTasks keyStorage = null)
     : this(symmetricAlgorithmName)
 {
     ResolveKeyStorage(symmetricKeyLocation, symmetricKeyLocationStrategy, keyStorage);
     InitializeAsymmetricKeys(certificate);
 }
Exemplo n.º 8
0
 public KeyedHasher(
     X509Certificate2 certificate,
     string keyLocation = null,
     IKeyLocationStrategy keyLocationStrategy = null,
     IKeyStorageTasks keyStorage = null,
     string hashAlgorithmName    = Algorithms.KeyedHash.Default,
     IHashAlgorithmFactory hashAlgorithmFactory = null)
     : this(hashAlgorithmName, hashAlgorithmFactory)
 {
     ResolveKeyStorage(keyLocation, keyLocationStrategy, keyStorage);
     InitializeAsymmetricKeys(certificate);
 }
Exemplo n.º 9
0
        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);
        }