gpt4 book ai didi

c# - 使用 Base64 编码将字节数组转换为 SecureString 的安全方法

转载 作者:行者123 更新时间:2023-12-04 04:15:47 27 4
gpt4 key购买 nike

我有一个 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 不安全,现在基本上不应该使用。曾经。它没有针对任何有意义的攻击实现任何有用的保护。

关于c# - 使用 Base64 编码将字节数组转换为 SecureString 的安全方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60721729/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com