PBKDF2加密
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加密的更多相关文章
- PBKDF2加密的实现
PBKDF2(Password-Based Key Derivation Function). 通过哈希算法进行加密.由于哈希算法是单向的,能够将不论什么大小的数据转化为定长的"指纹&quo ...
- PHP & JAVA 实现 PBKDF2 加密算法
PHP代码: /** * PBKDF2 加密函数 * 参考标准 * @link https://www.ietf.org/rfc/rfc2898.txt * * php官方函数将在php5.5发布 * ...
- Redis缓存数据库安全加固指导(二)
背景 在众多开源缓存技术中,Redis无疑是目前功能最为强大,应用最多的缓存技术之一,参考2018年国外数据库技术权威网站DB-Engines关于key-value数据库流行度排名,Redis暂列第一 ...
- ASP.NET Core搭建多层网站架构【2-公共基础库】
2020/01/28, ASP.NET Core 3.1, VS2019,Newtonsoft.Json 12.0.3, Microsoft.AspNetCore.Cryptography.KeyDe ...
- 密码学系列之:1Password的加密基础PBKDF2
目录 简介 PBKDF2和PBKDF1 PBKDF2的工作流程 详解PBKDF2的key生成流程 HMAC密码碰撞 PBKDF2的缺点 总结 简介 1password是一个非常优秀的密码管理软件,有了 ...
- JS加密库Crypto-JS SEA加密
http://www.seacha.com/tools/aes.html 在该网站测试 CryptoJS有很多加密方式网上查阅后有 CryptoJS (crypto.js) 为 JavaScript ...
- 【转】对抗拖库 ―― Web 前端慢加密
0×00 前言 天下武功,唯快不破.但密码加密不同.算法越快,越容易破. 0×01 暴力破解 密码破解,就是把加密后的密码还原成明文密码.似乎有不少方法,但最终都得走一条路:暴力穷举.也许你会说还可以 ...
- [转载] TLS协议分析 与 现代加密通信协议设计
https://blog.helong.info/blog/2015/09/06/tls-protocol-analysis-and-crypto-protocol-design/?from=time ...
- C#简单的加密类
1.加密 public class EncryptHepler { // 验值 static string saltValue = "XXXX"; // 密码值 static st ...
随机推荐
- iOS-获取当前网页的 url 和 title 和 html
本文转载至 http://www.th7.cn/Program/IOS/201310/156916.shtml @property (strong,nonatomic)UIWebView *web ...
- 【BZOJ2799】[Poi2012]Salaries 乱搞
[BZOJ2799][Poi2012]Salaries Description 给出一棵n个结点的有根树,结点用正整数1~n编号.每个结点有一个1~n的正整数权值,不同结点的权值不相同,并且一个结点的 ...
- 【BZOJ2213】[Poi2011]Difference DP
[BZOJ2213][Poi2011]Difference Description A word consisting of lower-case letters of the English alp ...
- N - Broken Keyboard (a.k.a. Beiju Text)(DFS,链表)
N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS Memory Limit:0KB 64bit IO Format:% ...
- 160817、Java数据类型以及变量的定义
Java 是一种强类型的语言,声明变量时必须指明数据类型.变量(variable)的值占据一定的内存空间.不同类型的变量占据不同的大小. Java中共有8种基本数据类型,包括4 种整型.2 种浮点型. ...
- SharePoint服务器端对象模型 之 序言
对于刚刚开始接触SharePoint的开发人员,即使之前有较为丰富的ASP.NET开发经验,在面对SharePoint时候可能也很难找到入手的方向.对于任何一种开发平台而言,学习开发的过程大致会包括: ...
- (转)免费天气预报接口API以及全国所有地区代码!!
国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...
- 前端基础 & Bootstrap框架
Bootstrap介绍 Bootstrap是Twitter开源的基于HTML.CSS.JavaScript的前端框架. 它是为实现快速开发Web应用程序而设计的一套前端工具包. 它支持响应式布局,并且 ...
- bzoj3007 解救小云公主
3007: 解救小云公主 Time Limit: 5 Sec Memory Limit: 512 MB Submit: 159 Solved: 71 [id=3007" style=&q ...
- SPDY
转载SPDY 是什么 SPDY 是 Google 开发的基于传输控制协议 (TCP) 的应用层协议 ,开发组正在推动 SPDY 成为正式标准(现为互联网草案).SPDY 协议旨在通过压缩.多路复用和优 ...