【发布时间】:2012-03-21 10:29:07
【问题描述】:
我有一个现有的数据格式,其中部分数据以 CFB 模式下的 AES 加密。明文数据长度和加密数据长度相同。
在 C# 中,我所采取的几乎每个角度似乎都期望加密长度是块大小的倍数......所以我在尝试解密数据时遇到异常。
在研究解决方案时,我使用了 Crypto++ 并编写了一个快速的 C++ 应用程序,它成功地解密了数据,所以我很确定我使用了正确的算法、密钥和 IV。这很好用,但如果可能的话,我想将所有内容都保留在 C# 中。有什么建议吗?
下面的工作 C++ 代码:
//define key
unsigned char key[16];
//populate key
//...
//define iv
unsigned char iv[16];
//populate iv
//...
std::ifstream inFile;
//open file
inFile.open("file.aes",ios::binary );
//get file size
inFile.seekg(0,ios::end);
int fileSize = (int) inFile.tellg();
inFile.seekg(offset, ios::beg);
//read/close file
char* inBytes = new char[fileSize];
inFile.read(inBytes,fileSize);
inFile.close();
//configure decryption
CFB_Mode<AES>::Decryption cfbDecryption(key, 16, iv);
//populate output bytes
char* outBytes = new char[fileSize];
cfbDecryption.ProcessData((byte*) outBytes,(byte*) inBytes,fileSize);
//open/write/close output file
std::ofstream outFile;
outFile.open("out.dec");
outFile.write(outBytes,fileSize);
outFile.close();
delete[] inBytes;
【问题讨论】:
-
你能发布你尝试过的C#代码和你得到的异常吗?
-
你检查this问题的答案了吗?
-
@GregS 说 q & a 可以使用一些爱,如果我没记错的话,它基本上是实现
-
@GregS 呃,那下面说不支持 CFB 的那部分呢?
-
@owlstead:我已经编辑了这个问题并包含了一个返回这个答案的链接。
标签: c# c++ encryption aes