c# - 这种加密和解密安全吗?
问题描述
我已经构建了 Windows 应用 PasswordManager。我正在使用 AESManaged 加密和解密密码。这有多安全?我试图实现 StringCipher.Encrypt(plainText, password) 和 StringCipher.Decrypt(encryptedText, password) 但无法弄清楚。
任何帮助将不胜感激。
谢谢
public class StringCipher
{
public static string Encrypt(string input)
{
return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(input)));
}
public static byte[] Encrypt(byte[] input)
{
PasswordDeriveBytes pdb = new PasswordDeriveBytes("hjiweykaksd", new byte[] { 0x43, 0x87, 0x23, 0x72, 0x45, 0x56, 0x68, 0x14, 0x62, 0x84 });
MemoryStream ms = new MemoryStream();
Aes aes = new AesManaged();
aes.Key = pdb.GetBytes(aes.KeySize / 8);
aes.IV = pdb.GetBytes(aes.BlockSize / 8);
CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(input, 0, input.Length);
cs.Close();
return ms.ToArray();
}
public static string Decrypt(string input)
{
return Encoding.UTF8.GetString(Decrypt(Convert.FromBase64String(input)));
}
public static byte[] Decrypt(byte[] input)
{
PasswordDeriveBytes pdb = new PasswordDeriveBytes("hjiweykaksd", new byte[] { 0x43, 0x87, 0x23, 0x72, 0x45, 0x56, 0x68, 0x14, 0x62, 0x84 });
MemoryStream ms = new MemoryStream();
Aes aes = new AesManaged();
aes.Key = pdb.GetBytes(aes.KeySize / 8);
aes.IV = pdb.GetBytes(aes.BlockSize / 8);
CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(input, 0, input.Length);
cs.Close();
return ms.ToArray();
}
}
解决方案
推荐阅读
- substrate - 基板官方安装指南
- python - Flask ImportError:无法在heroku上导入名称'app'
- python - [Errno 2]:即使文件存在,也没有此类文件或目录错误
- javascript - 当我尝试向其添加 ++ 运算符时,它在 JS 中不起作用
- clojure - 如何避免 Clojure 中嵌套的“for”函数?
- typescript - 为什么这里有“隐式任何返回类型”错误?
- r - 用 ggplot2 绘制环境函数
- python - 如何根据python脚本中的标签值($VARIABLE)“获取”某些环境变量
- vulkan - 如何获得并行 GPU 像素渲染?用于体素光线追踪
- python - Django 在特定 URL 上提供服务 - 相对 URL 已损坏