private void RunTrip(byte[] entropy, DataProtectionScope scope, IProtector protector) { var encrypted = protector.Protect(_sampleBytes, entropy, scope); var unencrypted = protector.Unprotect(encrypted, entropy, scope); var result = Encoding.UTF8.GetString(unencrypted); Assert.Equal(SampleText, result); }
public static async Task TestPassword <T>(this IProtector <T> protector, T raw) { ProtectionKey key = new ProtectionKey { Password = "******" }; var pro = await protector.Protect(raw, key); Assert.IsFalse(await protector.IsProtected(raw)); Assert.IsTrue(await protector.IsProtected(pro)); var depro = await protector.Deprotect(pro, key); Assert.IsFalse(await protector.IsProtected(depro)); depro.ShouldDeepEqual(raw); /*await Assert.ThrowsExceptionAsync<ProtectionException>(() => protector.Deprotect(pro, new ProtectionKey * { * Password = "******" * }));*/ }
protected static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope) => _protector.Protect(userData, optionalEntropy, scope);
public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope) { return(_protector.Protect(userData, optionalEntropy, scope)); }