如何使用Rfc2898DeriveBytes解密下面的函数字符串? [英] How can I decrypt below functions string with Rfc2898DeriveBytes?

查看:494
本文介绍了如何使用Rfc2898DeriveBytes解密下面的函数字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解密使用以下功能加密的字符串?

  private static byte [] salt = new byte [] {23,21,32,33,46,59,60,74}; 
private static int iterations = 1000;
private static int cb = 32;

public static string GetEncrypt(string plainText)
{
Rfc2898DeriveBytes k = new Rfc2898DeriveBytes(plainText,salt,iterations);
byte [] data = k.GetBytes(cb);
return Convert.ToBase64String(data);
}


解决方案

你不能。你误解了 Rfc2898DeriveBytes 的目的。这并不意味着是一种可逆的加密算法 - 它只是一种导出的方法,然后您可以在另一种加密算法中使用。



想法是你要求一个密码,将它(盐)转换成加密密钥,并使用该密钥加密数据(例如,使用 TripleDES )然后,再次请求密码,使用相同的盐生成相同的密钥,然后可以使用它来解密加密的数据。



p>

阅读 RFC 2898 了解更多信息。


How can I decrypt string that is encrypted with below function?

private static byte[] salt = new byte[] { 23, 21, 32, 33, 46, 59, 60, 74 };
private static int iterations = 1000;
private static int cb = 32;

public static string GetEncrypt(string plainText)
{
    Rfc2898DeriveBytes k = new Rfc2898DeriveBytes(plainText, salt, iterations);
    byte[] data = k.GetBytes(cb);
    return Convert.ToBase64String(data);
}

解决方案

You can't. You've misunderstood the purpose of Rfc2898DeriveBytes. It's not meant to be an reversible encryption algorithm - it's just meant to be a way of deriving a key which you then use within another encryption algorithm.

The idea is that you ask for a password, convert it (with a salt) into an encryption key, and use that key to encrypt the data (e.g. with TripleDES).

Then later, you ask for the password again, use the same salt to generate the same key, and then you can use that to decrypt the encrypted data.

Read RFC 2898 for more information.

这篇关于如何使用Rfc2898DeriveBytes解密下面的函数字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆