我需要使用AES 192加密文件,然后通过套接字将其发送给客户端。
我正在使用以下代码来加密文件:
string outputFile = "crypted";
//Confidentiality
RijndaelManaged AES192Confidentiality = new RijndaelManaged();
AES192Confidentiality.KeySize = 192;
AES192Confidentiality.BlockSize = 192;
AES192Confidentiality.IV = ConfIV;
AES192Confidentiality.Key = ConfKey;
AES192Confidentiality.Mode = CipherMode.CBC;
FileStream inputFileStream = new FileStream(par.GetFilePath(), FileMode.Open, FileAccess.Read);
FileStream outputFileStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
byte[] inputFileData = new byte[(int)inputFileStream.Length];
inputFileStream.Read(inputFileData, 0, (int)inputFileStream.Length);
CryptoStream encryptStream = new CryptoStream(outputFileStream, AES192Confidentiality.CreateEncryptor(), CryptoStreamMode.Write);
encryptStream.Write(inputFileData, 0, (int)inputFileStream.Length);
encryptStream.FlushFinalBlock();
encryptStream.Close();
我想知道现在如何通过套接字发送此加密的临时文件,以便接收器可以重建文件并对其进行解密。
有人可以给我一些教程或指南吗?
谢谢大家
最佳答案
您可以为套接字创建NetworkStream的实例,然后调用encryptStream.CopyTo(myNetworkStream);