Exemple #1
0
        /// <inheritdoc />
        public void StoreElement(XElement element, string friendlyName)
        {
            using var scope = _provider.CreateScope();
            var context = scope.ServiceProvider.GetRequiredService <TContext>();
            var key     = new ProtectionKey
            {
                FriendlyName = friendlyName,
                XmlValue     = element.ToString(SaveOptions.DisableFormatting)
            };

            context.Set <ProtectionKey>().Add(key);
            _logger.LogSavingKeyToDbContext(friendlyName, typeof(TContext).Name);
            context.SaveChanges();
        }
Exemple #2
0
        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 = "******"
             * }));*/
        }