public void CanEncryptData() { byte[] userData = { 0, 1, 2, 3, 4, 1, 2, 3, 4 }; DataProtectionCryptographyService svc = new DataProtectionCryptographyService(); byte[] result = svc.EncryptSymmetric(userData); byte[] restored = ProtectedData.Unprotect(result, null, DataProtectionScope.CurrentUser); Assert.AreEqual(9, restored.Length, "Restored data is not correct."); for (int i = 0; i < userData.Length; i++) { Assert.AreEqual(userData[i], restored[i], "The encryption failed."); } }
public void EncryptsUsingEntropy() { byte[] userData = { 0, 1, 2, 3, 4, 1, 2, 3, 4 }; byte[] entropy = { 1, 2, 3, 4 }; NameValueCollection settings = new NameValueCollection(); settings["Entropy"] = Convert.ToBase64String(entropy); DataProtectionCryptographyService svc = new DataProtectionCryptographyService(); svc.Configure(settings); byte[] cipherData = svc.EncryptSymmetric(userData); byte[] recovered = ProtectedData.Unprotect(cipherData, entropy, DataProtectionScope.CurrentUser); Assert.AreEqual(Convert.ToBase64String(userData), Convert.ToBase64String(recovered)); }
public void EncryptFailsIfNullData() { DataProtectionCryptographyService svc = new DataProtectionCryptographyService(); svc.EncryptSymmetric(null); }