gpt4 book ai didi

c# - 是否有将 AES 256 加密实现为流的 .NET 加密库?

转载 作者:太空狗 更新时间:2023-10-29 22:28:36 26 4
gpt4 key购买 nike

我希望能够在数据流式传输到磁盘或从磁盘流式传输时加密/解密数据。我知道我可以编写自己的 Stream 并在那里实现加密,但我不想冒险做错。有没有以类似于以下代码的方式工作的库?

byte[] encryptionKey = ;
byte[] initVector = ;

var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write);
var encryptionStream = new AesEncryptionStream(fileStream, initVector, encryptionKey);
var gzStream = new GZipStream(encryptionStream, CompressionMode.Compress);
var writer = new BinaryWriter(gzStream);

最佳答案

您正在寻找 RijndaelManagedCryptoStream 类:

var aes = new RijndaelManaged { Key = ..., IV = ... };

using (var encryptor = aes.CreateEncryptor())
using (var cryptoStream = new CryptoStream(gzStream, encryptor, CryptoStreamMode.Write))
using (var writer = new BinaryWriter(cryptoStream)) {
...
}

关于c# - 是否有将 AES 256 加密实现为流的 .NET 加密库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5031508/

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