Пример #1
0
 private static void ValidateMode(DpapiStorageMode mode)
 {
     if (!Enum.IsDefined(typeof(DpapiStorageMode), mode))
     {
         throw new ArgumentOutOfRangeException("mode", SR.ExceptionOutOfRangeDpapiStorageMode);
     }
 }
Пример #2
0
        public void EncryptAndDecryptMachineModeWithMissingEntropy()
        {
            DpapiStorageMode   mode  = DpapiStorageMode.Machine;
            DpapiCryptographer dpapi = new DpapiCryptographer(mode);

            dpapi.Encrypt(this.plainText);
        }
Пример #3
0
        public void EncryptAndDecryptUserMode()
        {
            DpapiStorageMode   mode  = DpapiStorageMode.User;
            DpapiCryptographer dpapi = new DpapiCryptographer(mode);

            byte[] cipherText = dpapi.Encrypt(this.plainText);

            Assert.IsFalse(CryptographyUtility.CompareBytes(this.plainText, cipherText));

            byte[] decryptedText = dpapi.Decrypt(cipherText);

            Assert.IsTrue(CryptographyUtility.CompareBytes(this.plainText, decryptedText));
        }
Пример #4
0
        public void Properties()
        {
            DpapiStorageMode mode = DpapiStorageMode.Machine;

            byte[] entropy = new byte[] { 0, 1, 2, 3, 4 };

            DpapiSettingsData data = new DpapiSettingsData();

            data.Mode    = mode;
            data.Entropy = entropy;

            Assert.AreEqual(mode, data.Mode);
            Assert.AreEqual(entropy, data.Entropy);
        }
Пример #5
0
        public void Properties()
        {
            string           name = "name";
            DpapiStorageMode mode = DpapiStorageMode.User;

            byte[] machineEntropy = new byte[16];
            CryptographyUtility.GetRandomBytes(machineEntropy);

            DpapiSymmetricCryptoProviderData data = new DpapiSymmetricCryptoProviderData();

            data.Name = name;

            Assert.AreEqual(name, data.Name, "name");
            Assert.AreEqual(typeof(DpapiSymmetricCryptoProvider).AssemblyQualifiedName, data.TypeName, "type");

            DpapiSettingsData dpapiData = new DpapiSettingsData();

            dpapiData.Mode          = mode;
            dpapiData.Entropy       = machineEntropy;
            data.DataProtectionMode = dpapiData;
            Assert.AreEqual(mode, data.DataProtectionMode.Mode, "Mode");
            Assert.IsTrue(CryptographyUtility.CompareBytes(machineEntropy, dpapiData.Entropy), "Entropy");
        }
Пример #6
0
 /// <summary>
 /// <para>Initialize a new instnace of the <see cref="DpapiSettingsData"/> class with entropy and a <see cref="DpapiStorageMode"/>.</para>
 /// </summary>
 /// <param name="entropy">
 /// <para>The machine entropy</para>
 /// </param>
 /// <param name="mode">
 /// <para>One of the <see cref="DpapiStorageMode"/> values.</para>
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <para>The value provided was out of the excepted valid ranges for <see cref="DpapiStorageMode"/>.</para>
 /// </exception>
 public DpapiSettingsData(byte[] entropy, DpapiStorageMode mode)
 {
     ValidateMode(mode);
     this.mode = mode;
     this.entropy = entropy;
 }
Пример #7
0
 private static void ValidateMode(DpapiStorageMode mode)
 {
     if (!Enum.IsDefined(typeof(DpapiStorageMode), mode))
     {
         throw new ArgumentOutOfRangeException("mode", SR.ExceptionOutOfRangeDpapiStorageMode);
     }
 }
Пример #8
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="DpapiCryptographer"/> class with a <see cref="DpapiStorageMode"/>.</para>
 /// </summary>
 /// <param name="storageMode"><para>One of the <see cref="DpapiStorageMode"/> values.</para></param>
 public DpapiCryptographer(DpapiStorageMode storageMode)
 {
     this.storeMode = storageMode;
 }
Пример #9
0
 /// <summary>
 /// <para>Initialize a new instnace of the <see cref="DpapiSettingsData"/> class with entropy and a <see cref="DpapiStorageMode"/>.</para>
 /// </summary>
 /// <param name="entropy">
 /// <para>The machine entropy</para>
 /// </param>
 /// <param name="mode">
 /// <para>One of the <see cref="DpapiStorageMode"/> values.</para>
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <para>The value provided was out of the excepted valid ranges for <see cref="DpapiStorageMode"/>.</para>
 /// </exception>
 public DpapiSettingsData(byte[] entropy, DpapiStorageMode mode)
 {
     ValidateMode(mode);
     this.mode    = mode;
     this.entropy = entropy;
 }
Пример #10
0
 private DpapiSettings()
 {
     mode = DpapiStorageMode.None;
 }
Пример #11
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="DpapiCryptographer"/> class with a <see cref="DpapiStorageMode"/>.</para>
 /// </summary>
 /// <param name="storageMode"><para>One of the <see cref="DpapiStorageMode"/> values.</para></param>
 public DpapiCryptographer(DpapiStorageMode storageMode)
 {
     this.storeMode = storageMode;
 }
Пример #12
0
 private DpapiSettings()
 {
     mode = DpapiStorageMode.None;
 }