gpt4 book ai didi

c# - AES 256文件加密c#

转载 作者:太空宇宙 更新时间:2023-11-03 21:44:43 25 4
gpt4 key购买 nike

我似乎找不到使用 AES 256 加密在 c# 中加密文件的干净示例

有没有人有一些示例代码?

最佳答案

这是对上述问题的回答

 UnicodeEncoding ue = new UnicodeEncoding();

byte[] key = ue.GetBytes(password);
string cryptFile = outputFile;
using (FileStream fileCrypt = new FileStream(cryptFile, FileMode.Create))
{
using (AesManaged encrypt = new AesManaged())
{
using (CryptoStream cs = new CryptoStream(fileCrypt, encrypt.CreateEncryptor(key, key), CryptoStreamMode.Write))
{
using (FileStream fileInput = new FileStream(inputFile, FileMode.Open))
{
encrypt.KeySize = 256;
encrypt.BlockSize = 128;
int data;
while ((data = fileInput.ReadByte()) != -1)
cs.WriteByte((byte)data);
}
}
}
}

关于c# - AES 256文件加密c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17627326/

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