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();
}

PBKDF2加密的更多相关文章

  1. PBKDF2加密的实现

    PBKDF2(Password-Based Key Derivation Function). 通过哈希算法进行加密.由于哈希算法是单向的,能够将不论什么大小的数据转化为定长的"指纹&quo ...

  2. PHP & JAVA 实现 PBKDF2 加密算法

    PHP代码: /** * PBKDF2 加密函数 * 参考标准 * @link https://www.ietf.org/rfc/rfc2898.txt * * php官方函数将在php5.5发布 * ...

  3. Redis缓存数据库安全加固指导(二)

    背景 在众多开源缓存技术中,Redis无疑是目前功能最为强大,应用最多的缓存技术之一,参考2018年国外数据库技术权威网站DB-Engines关于key-value数据库流行度排名,Redis暂列第一 ...

  4. ASP.NET Core搭建多层网站架构【2-公共基础库】

    2020/01/28, ASP.NET Core 3.1, VS2019,Newtonsoft.Json 12.0.3, Microsoft.AspNetCore.Cryptography.KeyDe ...

  5. 密码学系列之:1Password的加密基础PBKDF2

    目录 简介 PBKDF2和PBKDF1 PBKDF2的工作流程 详解PBKDF2的key生成流程 HMAC密码碰撞 PBKDF2的缺点 总结 简介 1password是一个非常优秀的密码管理软件,有了 ...

  6. JS加密库Crypto-JS SEA加密

    http://www.seacha.com/tools/aes.html 在该网站测试 CryptoJS有很多加密方式网上查阅后有 CryptoJS (crypto.js) 为 JavaScript ...

  7. 【转】对抗拖库 ―― Web 前端慢加密

    0×00 前言 天下武功,唯快不破.但密码加密不同.算法越快,越容易破. 0×01 暴力破解 密码破解,就是把加密后的密码还原成明文密码.似乎有不少方法,但最终都得走一条路:暴力穷举.也许你会说还可以 ...

  8. [转载] TLS协议分析 与 现代加密通信协议设计

    https://blog.helong.info/blog/2015/09/06/tls-protocol-analysis-and-crypto-protocol-design/?from=time ...

  9. C#简单的加密类

    1.加密 public class EncryptHepler { // 验值 static string saltValue = "XXXX"; // 密码值 static st ...

随机推荐

  1. R-ArcGIS探秘(1)安装以及Sample执行

    在今年的全球用户大会上,Esri官方发布了R-ArcGIS的官方演示样例,在ArcMap和ArcGIS pro中,直接通过Toolbox能够调用R的分析工具包,将R的分析能力直接作用在ArcGIS上面 ...

  2. IDLE崩溃:IDLE's subprocess didn't make connection. Either IDLE can't start a...

    今天在测试Python脚本的时候,突然间发现,脚本不能启动了,还弹出了“IDLE's subprocess didn't make connection. Either IDLE can't star ...

  3. CodeIgniter框架——源码分析之CodeIgniter.php

    CodeIgniter.php可以说是CI的核心,大部分MVC的流程都是在这个文件夹中处理的,其中加载了很多外部文件,完成CI的一次完整流程. 首先是定义了CI的版本(此处为CI 2.2.0),接下来 ...

  4. timus1716(概率dp)

    题意无比诡异. http://acm.timus.ru/problem.aspx?space=1&num=1716 俄罗斯的英文简直把我吓尿. 题意是对于输入:X1X2X3X4(Xi为YES或 ...

  5. Kotlin——中级篇(一):类(class)详解

    在任何一门面向对象编程的语言里,类(class)是非常基础.但也是非常重要的一项组成,通俗的说就是万般皆对象,而所说的对象就是我们生成的类.Kotlin也是如此,下面详细为大家介绍Kotlin中的类的 ...

  6. 一、docker临时记录

    docker 临时记录(阿里云centos7.2.1511 ) 查看系统版本号 适用于Redhat/CentOS: [root@iz2zecm4ndtkaue32tynx5z ~]# cat /etc ...

  7. 巨蟒python全栈开发linux之centos4

    1.linux虚拟环境1-4 2.linux运行crm代码

  8. js的简单的逻辑算法题

    比如题目:寻找1~1000之内,所有能被5整除.或者能被6整除的数字 1 for(var i = 1 ; i <= 1000 ; i++){ 2  if(i % 5 == 0 || i % 6 ...

  9. 0x03 MySQl 库操作

    一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信息等performance_schema: MyS ...

  10. DOM 常见事件

    onclick //当用户点击某个对象时调用的事件句柄. ondblclick //当用户双击某个对象时调用的事件句柄. onfocus //元素获得焦点. onblur //元素失去焦点. 应用场景 ...