示例#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));
        }
        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;
 }