加密大型文件花费太多时间

发布于 2025-01-24 14:35:39 字数 928 浏览 2 评论 0原文

我正在尝试使用AES 128加密和解密文件。一切正常,但是要加密仅165 kb的文件需要太多时间。我检查了整个Internet,并尝试使用不同的策略,但是结果仍然需要1分钟才能加密165KB的文件。

阅读和加密方式

string keyStr = "abcdefghijklmnop";
byte key[16];
charToByte(key, keyStr.c_str());
//Key expansion  
word w[4 * (Nr + 1)];
KeyExpansion(key, w);

bitset<128> data;
byte plain[16];

//Encrypt the file s.csv to s.csv.enc  
ifstream in;
ofstream out;
in.open("s.csv", ios::binary);
out.open("s.csv.enc", ios::binary);

while (in.read((char*)&data, sizeof(data)))
{
    divideToByte(plain, data);
    encrypt(plain, w);
    data = mergeByte(plain);
    out.write((char*)&data, sizeof(data));
    data.reset();  //Set 0  
}
in.close();
out.close();

这是我从中获取代码的 : https://programmer.group/c-implementation-of-aes-加密-algorithms.html

任何帮助都将受到赞赏。

I am trying to encrypt and decrypt a file using aes 128. Everything works fine but it takes too much time to encrypt a file which is just 165 kb. I checked the whole internet and tried to use different tactics but the result is still same takes 1 minute to encrypt a 165kb file.

here is how I do the reading and encrypting

string keyStr = "abcdefghijklmnop";
byte key[16];
charToByte(key, keyStr.c_str());
//Key expansion  
word w[4 * (Nr + 1)];
KeyExpansion(key, w);

bitset<128> data;
byte plain[16];

//Encrypt the file s.csv to s.csv.enc  
ifstream in;
ofstream out;
in.open("s.csv", ios::binary);
out.open("s.csv.enc", ios::binary);

while (in.read((char*)&data, sizeof(data)))
{
    divideToByte(plain, data);
    encrypt(plain, w);
    data = mergeByte(plain);
    out.write((char*)&data, sizeof(data));
    data.reset();  //Set 0  
}
in.close();
out.close();

I took the code from:
https://programmer.group/c-implementation-of-aes-encryption-algorithms.html

any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文