Rfc2898DeriveBytes 的 pbkdf2加密

relive8 2016-03-21 11:05:27
哪位大神帮忙看看pbkdf2加密问题
密码:123456 salt : a3xfJQ4X9ynk0kfYt4SPPA==
由于新老系统切换,
老系统用的是 Node.js 加密方法 crypto.pbkdf2Sync(password, salt, 10000, 64) , 加密出来的密码是:
GDLavfTOzNAG/DoWKJQ89H9S7nqPqA9wK8rgGFrydvpDTLCLkAWznf7akHXZqUELBmLywUcLhdXMB6iglZcUWw==

我在.net中方法为:
Rfc2898DeriveBytes k3 = new Rfc2898DeriveBytes(password, System.Text.UTF8Encoding.Default.GetBytes("a3xfJQ4X9ynk0kfYt4SPPA=="), 10000) ;
byte[] answers = k3.GetBytes(64) ;
var pwd = Convert.ToBase64String(answers)
结果密码为:
T+xVcJJkLR0Q8UC+2EVUIEShvik4jGmyyC4/8hUAdbxEQKVHMnGSSo1yTHmi8B0JwCI5nLGdC4qwabkh5oadJA==
...全文
1610 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
skkj 2016-06-24
  • 打赏
  • 举报
回复
把 System.Text.UTF8Encoding.Default.GetBytes("a3xfJQ4X9ynk0kfYt4SPPA==") 改为 Convert.FromBase64String("a3xfJQ4X9ynk0kfYt4SPPA==")


            string password = "123456";

            int myIterations = 10000;

            // Create a byte array to hold the random value. 
            //byte[] saltBytes = new byte[8];
            //using (RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider())
            //{
            //    // Fill the array with a random value.
            //    rngCsp.GetBytes(saltBytes);
            //}

            byte[] saltBytes = Convert.FromBase64String("a3xfJQ4X9ynk0kfYt4SPPA==");

            Rfc2898DeriveBytes passwordEncryptedBytes = new Rfc2898DeriveBytes(password, saltBytes, myIterations);

            string salt = Convert.ToBase64String(saltBytes);
            string passwordEncrypted = Convert.ToBase64String(passwordEncryptedBytes.GetBytes(64));

            Console.WriteLine(salt);
            Console.WriteLine(passwordEncrypted);
            Console.ReadLine();

13,347

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET技术前瞻
社区管理员
  • .NET技术前瞻社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧