标签:密文 compare rap nuget write using pwd blank read
上篇文章scrypt加密password SCrypt对密码进行加密 中使用的是SCrypt,本篇使用SCrypt.Net,其实和SCrypt差不多,只不过是NuGet程序包管理器使用的一个是SCrypt,一个是SCrypt.Net.本文详细介绍SCrypt.Net的使用
1、新建项目ConsoleSCrypt,使用NuGet程序包管理器添加SCrypt.Net
2、Program.cs中添加如下代码:
using System; using System.Security.Cryptography; namespace ConsoleSCrypt { class Program { static void Main(string[] args) { #region SCrypt.Net.SCrypt Console.WriteLine("SCrypt.Net.BCrypt"); Scrypt.ScryptEncoder scrypt = new Scrypt.ScryptEncoder(); Scrypt.ScryptEncoder scrypt1 = new Scrypt.ScryptEncoder(4, 8, 1); Scrypt.ScryptEncoder scrypt2 = new Scrypt.ScryptEncoder(8, 16, 1, RandomNumberGenerator.Create()); string pwd = "SCrypt明文信息"; Console.WriteLine($"明文信息:{pwd}"); string result = scrypt.Encode(pwd); Console.WriteLine($"加密以后的密文:{result}"); //string pwd1 = "SCrypt明文信息111"; //Console.WriteLine($"明文信息:{pwd1}"); //string result1 = scrypt1.Encode(pwd1); //Console.WriteLine($"加密以后的密文:{result1}"); //string pwd2 = "SCrypt明文信息222"; //Console.WriteLine($"明文信息:{pwd2}"); //string result2 = scrypt2.Encode(pwd2); //Console.WriteLine($"加密以后的密文:{result2}"); bool isValid = scrypt.IsValid(result); Console.WriteLine($"加密以后的密文 isvalid:{isValid}"); bool isMatchpasswordAndpwd= scrypt.Compare("SCrypt明文信息", result); Console.WriteLine($"明文信息与加密以后的密文是否一致:{isMatchpasswordAndpwd}"); #endregion Console.ReadLine(); } } }
3、运行结果:
标签:密文 compare rap nuget write using pwd blank read
原文地址:https://www.cnblogs.com/1175429393wljblog/p/13203665.html