我有一个现有的数据格式,它的一部分以CFB模式下的AES加密。明文数据长度和加密数据长度相同。CFB中的C#AES加密,其中明文长度等于加密长度
在C#中,几乎每一个我所采取的角度似乎期待加密长度是块大小的整数倍,所以,我得到一个异常尝试解密数据。
在研究解决方案,我用加密+和写了一个快速的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#代码,你所得到的例外呢? – Xint0 2012-03-02 23:08:30
你有没有检查[这个]的答案(http://stackoverflow.com/questions/3142279/encrypt-data-with-c-sharp-aescryptoserviceprovider-crypted-with-bouncycastle-aes)的问题? – 2012-03-03 01:29:30
@GregS q&a可以使用一些爱,它基本上是实现,如果我没有错误 – 2012-03-03 12:32:35