c# - 使用 Base64 编码将字节数组转换为 SecureString 的安全方法
问题描述
我有一个byte[]
需要在 Base64 中编码并返回为SecureString
. 我目前的代码如下:
string privateString = Convert.ToBase64String(byteArray);
SecureString result = new SecureString();
foreach (char c in privateString)
{
result.AppendChar(c);
}
// wipe the byte array...
问题是调用Convert.ToBase64String
不安全,因为它创建了一个我无法销毁的托管字符串。有没有一种安全的方法来做到这一点?
解决方案
关于在没有中间字符串的情况下编码 base-64 数据的方法:System.Buffers.Text.Base64
. 然而!SecureString
不安全,现在基本上不应该使用。曾经。它没有针对任何有意义的攻击提供任何有用的保护。
推荐阅读
- python - 使用字典键捕获组的正则表达式
- node.js - Mongoose 聚合:如何使用 ejs 显示聚合结果
- sql - 有没有办法在左连接中实现计数
- javascript - 如何将字符串中每个单词的首字母大写?
- mysql - Sequelize 不支持 MySQL 8 身份验证协议,我不知道如何更改此协议
- javascript - 反应空白文本节点不能作为子节点出现
- python - 从数据框中选择其特定列值等于另一个数据框的列的行
- python - 实现 k-means 聚类算法时,np.linalg.norm 是否应该平方?
- arrays - 当您在循环中迭代数组时,如何知道数组中是否没有更多值
- netlogo - 如何创建与新创建的海龟的链接