password - the password that needs to be hashed. This should be converted
into a char array before passing.

salt- salt value that should append to the password.

iterations- no. of iterations to be done. This value can be used to adjust the speed of the algorithm.

keyLength- This is the required output length of the hashed function.

This function returns a byte array that needs to be converted into a string using a suitable hex encoder.

需要注意的是,加密的结果是字节数组。在存储到数据库的时候,可以转换为十六进制的字符串或者Base64字符串

        [Test]
public void Pbkdf2Test()
{ string saltString = "8291f825-5772-4b3b-a28c-18887099f6d4";
var array = Encoding.UTF8.GetBytes(saltString);
GetHexString(array, );
GetHexString(array, );
GetHexString(array,);
GetHexString(array,); var rfc2898DeriveBytes = new Rfc2898DeriveBytes("", array, );
var result2 = rfc2898DeriveBytes.GetBytes();
Console.WriteLine($"加密结果数组长度{result2.Length}");
var string2 = Convert.ToBase64String(result2);
Console.WriteLine(string2);
Console.WriteLine(string2.Length);
} public void GetHexString(byte[] array, int keyLength)
{
var rfc2898DeriveBytes = new Rfc2898DeriveBytes("", array, );
var result = rfc2898DeriveBytes.GetBytes(keyLength);
Console.WriteLine($"加密结果数组长度{result.Length}"); var hexString = ByteArrayToString(result);
Console.WriteLine(hexString);
Console.WriteLine("========Split========");
} public static string ByteArrayToString(byte[] ba)
{
var hex = new StringBuilder(ba.Length * );
foreach (var b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}

最新文章

  1. 构建高性能的MYSQL数据库系统
  2. HUSTOJ搭建实录
  3. SQL总结(三)其他查询
  4. iOS从不同页面跳转回到指定控制器
  5. Java_SSH项目主要步骤记录
  6. Cmd批处理语法实例
  7. CSS定位深入理解 完全掌握CSS定位 相对定位和绝对定位
  8. Docker学习总结之Run命令介绍
  9. Angular基础(二)
  10. Delphi中打开网页连接的几种方法
  11. MySql主从搭建详细步骤
  12. Java中 try--catch-- finally、throw、throws 的用法
  13. syzkaller 资料集合
  14. RabbitMQ学习之旅(一)
  15. Kinect v2 记录
  16. SpringMVC RedirectView的使用以及源码分析
  17. 多态时最好将基类的析构函数设为virtual、 C++中两个类相互包含引用问题 (转载)
  18. layer 弹出层 不居中
  19. BZOJ1822 Frozen Nova 冷冻波
  20. gpfs 内核错误

热门文章

  1. 时间格式转换 json 转 datetime js c#
  2. 爬虫实战【5】送福利!Python获取妹子图上的内容
  3. php学习笔记8--半边引号引发的问题
  4. Pycharm中目前用到的快捷键
  5. 利用jdk中工具完成Java程序监控方法记录
  6. js验证表单大全2
  7. 通过jdt解析spring mvc中url-类-方法的对应关系
  8. 不同格式的ip 统一转成ip列表
  9. Latex排版全解(转)
  10. TCP/IP/UDP 协议