/// <summary>
 /// Initializes a new instance of the <see cref="SymmetricAlgorithmProvider"/> class.
 /// </summary>
 /// <param name="algorithmType">The cryptographic algorithm type.</param>
 /// <param name="protectedKeyStream">Input <see cref="Stream"/> from which DPAPI-protected key is to be read.</param>
 /// <param name="protectedKeyProtectionScope"><see cref="DataProtectionScope"/> used to protect the key on disk. </param>
 /// <param name="instrumentationProvider">The <see cref="ISymmetricAlgorithmInstrumentationProvider"/> to use.</param>
 public SymmetricAlgorithmProvider(Type algorithmType,
                                   Stream protectedKeyStream,
                                   DataProtectionScope protectedKeyProtectionScope,
                                   ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
     : this(algorithmType, KeyManager.Read(protectedKeyStream, protectedKeyProtectionScope), instrumentationProvider)
 {
 }
		/// <summary>
		/// <para>Initialize a new instance of the <see cref="DpapiSymmetricCryptoProvider"/></para>
		/// </summary>
		/// <param name="scope"><para>One of the <see cref="DataProtectionScope"/> values.</para></param>
		/// <param name="entropy"><para>The entropy to salt the phrase.</para></param>
        /// <param name="instrumentationProvider">Instrumentation provider to use.</param>
		public DpapiSymmetricCryptoProvider(DataProtectionScope scope, byte[] entropy, ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
		{
            if (instrumentationProvider == null) throw new ArgumentNullException("instrumentationProvider");

			this.protectionScope = scope;
			this.entropy = entropy;
            this.instrumentationProvider = instrumentationProvider;
		}
示例#3
0
        /// <summary>
        /// <para>Initialize a new instance of the <see cref="DpapiSymmetricCryptoProvider"/></para>
        /// </summary>
        /// <param name="scope"><para>One of the <see cref="DataProtectionScope"/> values.</para></param>
        /// <param name="entropy"><para>The entropy to salt the phrase.</para></param>
        /// <param name="instrumentationProvider">Instrumentation provider to use.</param>
        public DpapiSymmetricCryptoProvider(DataProtectionScope scope, byte[] entropy, ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
        {
            if (instrumentationProvider == null)
            {
                throw new ArgumentNullException("instrumentationProvider");
            }

            this.protectionScope         = scope;
            this.entropy                 = entropy;
            this.instrumentationProvider = instrumentationProvider;
        }
示例#4
0
        public void SetUp()
        {
            nameFormatter           = new AppDomainNameFormatter(applicationInstanceName);
            instrumentationProvider = new SymmetricAlgorithmInstrumentationProvider(instanceName, true, true, nameFormatter);
            formattedInstanceName   = nameFormatter.CreateName(instanceName);
            totalSymmetricDecryptionPerformedCounter = new EnterpriseLibraryPerformanceCounter(SymmetricAlgorithmInstrumentationProvider.counterCategoryName, SymmetricAlgorithmInstrumentationProvider.TotalSymmetricDecryptionPerformedCounterName, formattedInstanceName);
            totalSymmetricEncryptionPerformedCounter = new EnterpriseLibraryPerformanceCounter(SymmetricAlgorithmInstrumentationProvider.counterCategoryName, SymmetricAlgorithmInstrumentationProvider.TotalSymmetricEncryptionPerformedCounterName, formattedInstanceName);

            stream   = CreateSymmetricKey();
            provider = new SymmetricAlgorithmProvider(typeof(RijndaelManaged), stream, DataProtectionScope.CurrentUser, instrumentationProvider);

            totalSymmetricDecryptionPerformedCounter.Clear();
            totalSymmetricEncryptionPerformedCounter.Clear();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SymmetricAlgorithmProvider"/> class.
        /// </summary>
        /// <param name="algorithmType">The symmetric algorithm type.</param>
        /// <param name="key">The <see cref="ProtectedKey"/> for the provider.</param>
        /// <param name="instrumentationProvider">The <see cref="ISymmetricAlgorithmInstrumentationProvider"/> to use.</param>
        public SymmetricAlgorithmProvider(Type algorithmType,
                                          ProtectedKey key,
                                          ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
        {
            if (instrumentationProvider == null)
            {
                throw new ArgumentNullException("instrumentationProvider");
            }
            if (algorithmType == null)
            {
                throw new ArgumentNullException("algorithmType");
            }
            if (!typeof(SymmetricAlgorithm).IsAssignableFrom(algorithmType))
            {
                throw new ArgumentException(Resources.ExceptionCreatingSymmetricAlgorithmInstance, "algorithmType");
            }

            this.algorithmType = algorithmType;

            this.key = key;

            this.instrumentationProvider = instrumentationProvider;
        }
示例#6
0
 /// <summary>
 /// <para>Initialize a new instance of the <see cref="DpapiSymmetricCryptoProvider"/></para>
 /// </summary>
 /// <param name="scope"><para>One of the <see cref="DataProtectionScope"/> values.</para></param>
 /// <param name="instrumentationProvider">Instrumentation provider to use.</param>
 public DpapiSymmetricCryptoProvider(DataProtectionScope scope, ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
     : this(scope, null, instrumentationProvider)
 {
 }
		/// <summary>
		/// <para>Initialize a new instance of the <see cref="DpapiSymmetricCryptoProvider"/></para>
		/// </summary>
		/// <param name="scope"><para>One of the <see cref="DataProtectionScope"/> values.</para></param>
        /// <param name="instrumentationProvider">Instrumentation provider to use.</param>
        public DpapiSymmetricCryptoProvider(DataProtectionScope scope, ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
            : this(scope, null, instrumentationProvider)
		{
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="SymmetricAlgorithmProvider"/> class.
		/// </summary>
		/// <param name="algorithmType">The cryptographic algorithm type.</param>
		/// <param name="protectedKeyStream">Input <see cref="Stream"/> from which DPAPI-protected key is to be read.</param>
		/// <param name="protectedKeyProtectionScope"><see cref="DataProtectionScope"/> used to protect the key on disk. </param>
        /// <param name="instrumentationProvider">The <see cref="ISymmetricAlgorithmInstrumentationProvider"/> to use.</param>
        public SymmetricAlgorithmProvider(Type algorithmType,
										  Stream protectedKeyStream,
                                          DataProtectionScope protectedKeyProtectionScope,
                                          ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
			: this(algorithmType, KeyManager.Read(protectedKeyStream, protectedKeyProtectionScope), instrumentationProvider) { }
		/// <summary>
		/// Initializes a new instance of the <see cref="SymmetricAlgorithmProvider"/> class.
		/// </summary>
		/// <param name="algorithmType">The symmetric algorithm type.</param>
		/// <param name="key">The <see cref="ProtectedKey"/> for the provider.</param>
        /// <param name="instrumentationProvider">The <see cref="ISymmetricAlgorithmInstrumentationProvider"/> to use.</param>
		public SymmetricAlgorithmProvider(Type algorithmType,
                                          ProtectedKey key,
                                          ISymmetricAlgorithmInstrumentationProvider instrumentationProvider)
		{
            if (instrumentationProvider == null) throw new ArgumentNullException("instrumentationProvider");
			if (algorithmType == null) throw new ArgumentNullException("algorithmType");
			if (!typeof(SymmetricAlgorithm).IsAssignableFrom(algorithmType)) throw new ArgumentException(Resources.ExceptionCreatingSymmetricAlgorithmInstance, "algorithmType");

			this.algorithmType = algorithmType;

			this.key = key;

            this.instrumentationProvider = instrumentationProvider;
		}