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 ...
随机推荐
- python3 - property的使用
传统的绑定属性值,会把属性暴露出去,而且无法检查参数是否合法,如下: class Test(object): def __int__(self,age): self.age = age 为了检查参数 ...
- [Spring MVC]学习笔记--FreeMarker的使用
还是先贴出该例子存于github上的位置 https://github.com/lemonbar/spring-mvc-freemarker Sping-Framework 的官方文档简单列出了在sp ...
- 关于angularjs的select下拉列表存在空白的解决办法
angularjs 的select的option是通过循环造成的,循环的方式可能有ng-option或者</option ng-repeat></option>option中 ...
- 解决asp.net中HTML中talbe的行高被内容撑的变高的问题
将asp.net页面中的如下语句: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- Java中Solr集群的测试
import org.apache.solr.client.solrj.impl.CloudSolrServer; import org.apache.solr.common.SolrInputDoc ...
- C# MD5加密与校验 引用
using System; using System.Security.Cryptography; using System.Text; class Example { // Hash an inpu ...
- Adjacency List
w Python Patterns - Implementing Graphs | Python.orghttps://www.python.org/doc/essays/graphs/ Graph ...
- C 和 C++ 的标准库分别有自己的 locale 操作方法,C 标准库的 locale 设定函数是 setlocale(),而 C++ 标准库有 locale 类和流对象的 imbue() 方法(gcc使用zh_CN.GBK,或者zh_CN.UTF-8,VC++使用Chinese_People's Republic of China.936或者65001.)
转自:http://zyxhome.org/wp/cc-prog-lang/c-stdlib-setlocale-usage-note/ [在此向原文作者说声谢谢!若有读者看到文章转载时请写该转载地址 ...
- (4.6)sql server索引缺失提示
SQLSERVER如何查看索引缺失 sql server索引缺失提示 当大家发现数据库查询性能很慢的时候,大家都会想到加索引来优化数据库查询性能, 但是面对一个复杂的SQL语句,找到一个优化的索引组合 ...
- 005-MYSQL数据库设计原则
1.核心原则 不在数据库做运算; cpu计算务必移至业务层; 控制列数量(字段少而精,字段数建议在20以内); 平衡范式与冗余(效率优先:往往牺牲范式) 拒绝3B(拒绝大sql语句:big sql.拒 ...