private static void ValidateMode(DpapiStorageMode mode) { if (!Enum.IsDefined(typeof(DpapiStorageMode), mode)) { throw new ArgumentOutOfRangeException("mode", SR.ExceptionOutOfRangeDpapiStorageMode); } }
public void EncryptAndDecryptMachineModeWithMissingEntropy() { DpapiStorageMode mode = DpapiStorageMode.Machine; DpapiCryptographer dpapi = new DpapiCryptographer(mode); dpapi.Encrypt(this.plainText); }
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); }
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"); }
/// <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; }
/// <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; }
private DpapiSettings() { mode = DpapiStorageMode.None; }