zwei1121

博客园 首页 新随笔 联系 订阅 管理
https://www.fishlee.net/tools/machinekeygenerator

https://stackoverflow.com/questions/46668192/how-to-implement-machinekey-in-asp-net-core-2-0

string pathToCryptoKeys = Path.Combine(environment.ContentRootPath, "dp_keys"); services.AddDataProtection() .PersistKeysToFileSystem(new System.IO.DirectoryInfo(pathToCryptoKeys));

 

validationKey = CreateKey(20);  

decryptionKey = CreateKey(24);  

      protected string CreateKey(int len)  

      {  

             byte[] bytes = new byte[len];  

             new RNGCryptoServiceProvider().GetBytes(bytes);  

               StringBuilder sb = new StringBuilder();  

               for(int i = 0; i < bytes.Length; i++)  

               {      

                    sb.Append(string.Format("{0:X2}",bytes[i]));  

               }  

               return sb.ToString();  

      }

 

<?xml version="1.0"?>

<configuration>

   <system.web>

     <machineKey validationKey="3FF1E929BC0534950B0920A7B59FA698BD02DFE8" decryptionKey="280450BB36319B474C996B506A95AEDF9B51211B1D2B7A77" decryption="3DES" validation="SHA1"/>

      </system.web>

</configuration>

 

http://www.fishlee.net/tools/machinekeygenerator

 

<machineKey validationKey="DABE4F61AC6312AFCEFBB6041CADE0CF45023D5F6FA9929F1EEC4613E5AFD6FF6429F98A4CE95107B8818EE1549BF51734402C54A311A90A70FAA0962E27CD28" decryptionKey="87A4EA0F216C2D8913E7C3D0483E20A2BDC56852225491D30B9BCA2CF3BD1A9B" validation="SHA1" decryption="AES" />

 

posted on 2018-05-18 14:54  zwei  阅读(172)  评论(0)    收藏  举报