using Microsoft.AspNetCore.DataProtection.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Session02
{
public class CustomXmlRepository : IXmlRepository
{
/// <summary>
/// 设置MachineKey这里的内容就是复制出xml文件的内容
/// </summary>
private readonly string keyContent =
@"<?xml version='1.0' encoding='utf-8'?>
<key id='6e0d77ae-807d-4dd5-9b33-1f364f6c1f3e' version='1'>
<creationDate>2018-07-25T07:01:39.5356164Z</creationDate>
<activationDate>2018-07-25T07:01:39.4800644Z</activationDate>
<expirationDate>2018-10-23T07:01:39.4800644Z</expirationDate>
<descriptor deserializerType='Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'>
<descriptor>
<encryption algorithm='AES_256_CBC' />
<validation algorithm='HMACSHA256' />
<masterKey p4:requiresEncryption='true' xmlns:p4='http://schemas.asp.net/2015/03/dataProtection'>
<!-- Warning: the key below is in an unencrypted form. -->
<value>lPUxFutB30oi1KU990Y5nKxeCBnHg7h1JX26nvDlpxdbYciXQr2gdUpLxrL52O/vg8Htrr9F3Xf2fqnVhhAjhw==</value>
</masterKey>
</descriptor>
</descriptor>
</key>";
public virtual IReadOnlyCollection<XElement> GetAllElements()
{
return GetAllElementsCore().ToList().AsReadOnly();
}
private IEnumerable<XElement> GetAllElementsCore()
{
yield return XElement.Parse(keyContent);
}
public virtual void StoreElement(XElement element, string friendlyName)
{
if (element == null)
{
throw new ArgumentNullException(nameof(element));
}
StoreElementCore(element, friendlyName);
}
private void StoreElementCore(XElement element, string filename)
{
}
}
}