aes256加密_一款十分强大的文件加密解密工具

明天推荐预告:一款好用的手机端视频播放器!

今天教程适合了解linux系统的你使用。

在市场上能找到许多用来保护文件的文档加密工具。今天我们将讨论一款叫做 “toplip” 的命令行文件加密解密工具。它是一款使用 AES256 强大加密方法的自由开源的加密工具。它同时也使用了 XTS-AES 设计以保护你的隐私数据。它还使用了 Scrypt,一种基于密码的密钥生成函数来保护你的密码免于暴力破解。

优秀的特性

相比于其它文件加密工具,toplip 自带以下独特且杰出的特性。

  • 非常强大的基于 XTS-AES256 的加密方法。
  • 合理的推诿
  • 加密并嵌入文件到图片(PNG/JPG)中。
  • 多重密码保护。
  • 可防护直接暴力破解。
  • 无可辨识的输出标记。
  • 开源(GPLv3)。

安装 toplip

没有什么需要安装的。toplip 是独立的可执行二进制文件。你所要做的仅是从 产品官方页面 下载最新版的 toplip 并赋予它可执行权限。为此你只要运行:

chmod +x toplip

使用

如果你不带任何参数运行 toplip,你将看到帮助页面。

./toplip
e6e4fdb13afa4bc5b8fbe67f5483ea24

请允许我给你展示一些例子。

为了达到指导目的,我建了两个文件 file1 和 file2。我同时也有 toplip 可执行二进制文件。我把它们全都保存进一个叫做 test 的目录。

aa3bd84a9f2c438890da5d06fde8d5a4

加密/解密单个文件

现在让我们加密 file1。为此,运行:

./toplip file1 > file1.encrypted

这行命令将让你输入密码。一旦你输入完密码,它就会加密 file1 的内容并将它们保存进你当前工作目录下一个叫做 file1.encrypted 的文件。

上述命令行的示例输出将会是这样:

This is toplip v1.20 (C) 2015, 2016 2 Ton Digital. Author: Jeff Marrison A showcase piece for the HeavyThing library. Commercial support available Proudly made in Cooroy, Australia. More info: https://2ton.com.au/toplip file1 Passphrase #1: generating keys...Done Encrypting...Done

为了验证文件是否的确经过加密,试着打开它你会发现一些随机的字符。

为了解密加密过的文件,像以下这样使用 -d 参数:

./toplip -d file1.encrypted

这行命令会解密提供的文档并在终端窗口显示内容。

为了保存文档而不是写入到标准输出,运行:

./toplip -d file1.encrypted > file1.decrypted

输入正确的密码解密文档。file1.encrypted 的所有内容将会存入一个叫做 file1.decrypted 的文档。

请不要用这种命名方法,我这样用仅仅是为了便于理解。使用其它难以预测的名字。

加密/解密多个文件

现在我们将使用两个分别的密码加密每个文件。

./toplip -alt file1 file2 > file3.encrypted

你会被要求为每个文件输入一个密码,使用不同的密码。

上述命令行的示例输出将会是这样:

This is toplip v1.20 (C) 2015, 2016 2 Ton Digital. Author: Jeff Marrison A showcase piece for the HeavyThing library. Commercial support available Proudly made in Cooroy, Australia. More info: https://2ton.com.au/toplip file2 Passphrase #1 : generating keys...Done file1 Passphrase #1 : generating keys...Done Encrypting...Done

上述命令所做的是加密两个文件的内容并将它们保存进一个单独的叫做 file3.encrypted 的文件。在保存中分别给予各自的密码。比如说如果你提供 file1 的密码,toplip 将复原 file1。如果你提供 file2 的密码,toplip 将复原 file2。

每个 toplip 加密输出都可能包含最多四个单独的文件,并且每个文件都建有各自独特的密码。由于加密输出放在一起的方式,一下判断出是否存在多个文档不是一件容易的事。默认情况下,甚至就算确实只有一个文件是由 toplip 加密,随机数据都会自动加上。如果指定了多于一个文件,每个都有自己的密码,那么你可以有选择性地独立解码每个文件,以此来否认其它文件存在的可能性。这能有效地使一个用户在可控的暴露风险下打开一个加密的捆绑文件包。并且对于敌人来说,在计算上没有一种低廉的办法来确认额外的秘密数据存在。这叫做“合理的推诿Plausible deniability”,是 toplip 著名的特性之一。

为了从 file3.encrypted 解码 file1,仅需输入:

./toplip -d file3.encrypted > file1.encrypted

你将会被要求输入 file1 的正确密码。

为了从 file3.encrypted 解码 file2,输入:

./toplip -d file3.encrypted > file2.encrypted

别忘了输入 file2 的正确密码。

使用多重密码保护

这是我中意的另一个炫酷特性。在加密过程中我们可以为单个文件提供多重密码。这样可以保护密码免于暴力尝试。

./toplip -c 2 file1 > file1.encrypted

这里,-c 2 代表两个不同的密码。上述命令行的示例输出将会是这样:

This is toplip v1.20 (C) 2015, 2016 2 Ton Digital. Author: Jeff Marrison A showcase piece for the HeavyThing library. Commercial support available Proudly made in Cooroy, Australia. More info: https://2ton.com.au/toplip file1 Passphrase #1: generating keys...Donefile1 Passphrase #2: generating keys...Done Encrypting...Done

正如你在上述示例中所看到的,toplip 要求我输入两个密码。请注意你必须提供两个不同的密码,而不是提供两遍同一个密码。

为了解码这个文件,这样做:

$ ./toplip -c 2 -d file1.encrypted > file1.decrypted This is toplip v1.20 (C) 2015, 2016 2 Ton Digital. Author: Jeff Marrison A showcase piece for the HeavyThing library. Commercial support available Proudly made in Cooroy, Australia. More info: https://2ton.com.au/toplip file1.encrypted Passphrase #1: generating keys...Donefile1.encrypted Passphrase #2: generating keys...DoneDecrypting...Done

将文件藏在图片中

将一个文件、消息、图片或视频藏在另一个文件里的方法叫做隐写术。幸运的是 toplip 默认包含这个特性。

为了将文件藏入图片中,像如下所示的样子使用 -m 参数。

$ ./toplip -m image.png file1 > image1.pngThis is toplip v1.20 (C) 2015, 2016 2 Ton Digital. Author: Jeff Marrison A showcase piece for the HeavyThing library. Commercial support available Proudly made in Cooroy, Australia. More info: https://2ton.com.au/toplip file1 Passphrase #1: generating keys...Done Encrypting...Done

这行命令将 file1 的内容藏入一张叫做 image1.png 的图片中。

要解码,运行:

$ ./toplip -d image1.png > file1.decrypted This is toplip v1.20 (C) 2015, 2016 2 Ton Digital. Author: Jeff Marrison A showcase piece for the HeavyThing library. Commercial support available Proudly made in Cooroy, Australia. More info: https://2ton.com.au/toplip image1.png Passphrase #1: generating keys...Done Decrypting...Done

增加密码复杂度

为了进一步使文件变得难以破译,我们可以像以下这样增加密码复杂度:

./toplip -c 5 -i 0x8000 -alt file1 -c 10 -i 10 file2 > file3.encrypted

上述命令将会要求你为 file1 输入十条密码,为 file2 输入五条密码,并将它们存入单个叫做 file3.encrypted 的文件。如你所注意到的,我们在这个例子中又用了另一个 -i 参数。这是用来指定密钥生成循环次数。这个选项覆盖了 scrypt 函数初始和最终 PBKDF2 阶段的默认循环次数 1。十六进制和十进制数值都是允许的。比如说 0x8000、10 等。请注意这会大大增加计算次数。

为了解码 file1,使用:

./toplip -c 5 -i 0x8000 -d file3.encrypted > file1.decrypted

为了解码 file2,使用:

./toplip -c 10 -i 10 -d file3.encrypted > file2.decrypted

如果感觉还不错,请大家关注我,点赞支持一下,勿做伸手党。

欢迎同时关注微信公众号:IT科技森

每天分享IT小技巧、科技数码新闻!

近期精品文章:

一个聚合类的快搜网站,适用于各类搜索!

网页视频及VIP视频——直接观看和下载神器!

一个app搞定各大直播平台!

一款好用的PC端视频播放器!

桌面端IOS模拟器!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
EVP_aes_256_cbc是OpenSSL库提供的一种加密算法,可以用于对大文件进行加密解密。下面是c++实现EVP_aes_256_cbc大文件加密解密的示例代码: ```c++ #include <openssl/evp.h> #include <iostream> #include <fstream> using namespace std; int aes_encrypt(const char *key, const char *iv, const char *infile, const char *outfile) { EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); if (!ctx) { cerr << "Error: EVP_CIPHER_CTX_new() failed" << endl; return -1; } // 初始化加密上下文 if (EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, (const unsigned char *)key, (const unsigned char *)iv) != 1) { cerr << "Error: EVP_EncryptInit_ex() failed" << endl; EVP_CIPHER_CTX_free(ctx); return -1; } // 打开输入文件 ifstream fin(infile, ios::binary); if (!fin.is_open()) { cerr << "Error: Cannot open input file" << endl; EVP_CIPHER_CTX_free(ctx); return -1; } // 打开输出文件 ofstream fout(outfile, ios::binary); if (!fout.is_open()) { cerr << "Error: Cannot create output file" << endl; fin.close(); EVP_CIPHER_CTX_free(ctx); return -1; } // 读取输入文件加密 const int BUFSIZE = 1024 * 1024; unsigned char inbuf[BUFSIZE]; unsigned char outbuf[BUFSIZE + EVP_CIPHER_block_size(EVP_aes_256_cbc())]; int inlen, outlen; while (!fin.eof()) { fin.read((char *)inbuf, BUFSIZE); inlen = fin.gcount(); if (EVP_EncryptUpdate(ctx, outbuf, &outlen, inbuf, inlen) != 1) { cerr << "Error: EVP_EncryptUpdate() failed" << endl; fin.close(); fout.close(); EVP_CIPHER_CTX_free(ctx); return -1; } fout.write((char *)outbuf, outlen); } // 结束加密 if (EVP_EncryptFinal_ex(ctx, outbuf, &outlen) != 1) { cerr << "Error: EVP_EncryptFinal_ex() failed" << endl; fin.close(); fout.close(); EVP_CIPHER_CTX_free(ctx); return -1; } fout.write((char *)outbuf, outlen); // 关闭文件加密上下文 fin.close(); fout.close(); EVP_CIPHER_CTX_free(ctx); return 0; } int aes_decrypt(const char *key, const char *iv, const char *infile, const char *outfile) { EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); if (!ctx) { cerr << "Error: EVP_CIPHER_CTX_new() failed" << endl; return -1; } // 初始化解密上下文 if (EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, (const unsigned char *)key, (const unsigned char *)iv) != 1) { cerr << "Error: EVP_DecryptInit_ex() failed" << endl; EVP_CIPHER_CTX_free(ctx); return -1; } // 打开输入文件 ifstream fin(infile, ios::binary); if (!fin.is_open()) { cerr << "Error: Cannot open input file" << endl; EVP_CIPHER_CTX_free(ctx); return -1; } // 打开输出文件 ofstream fout(outfile, ios::binary); if (!fout.is_open()) { cerr << "Error: Cannot create output file" << endl; fin.close(); EVP_CIPHER_CTX_free(ctx); return -1; } // 读取输入文件解密 const int BUFSIZE = 1024 * 1024 + EVP_CIPHER_block_size(EVP_aes_256_cbc()); unsigned char inbuf[BUFSIZE]; unsigned char outbuf[BUFSIZE]; int inlen, outlen; while (!fin.eof()) { fin.read((char *)inbuf, BUFSIZE); inlen = fin.gcount(); if (EVP_DecryptUpdate(ctx, outbuf, &outlen, inbuf, inlen) != 1) { cerr << "Error: EVP_DecryptUpdate() failed" << endl; fin.close(); fout.close(); EVP_CIPHER_CTX_free(ctx); return -1; } fout.write((char *)outbuf, outlen); } // 结束解密 if (EVP_DecryptFinal_ex(ctx, outbuf, &outlen) != 1) { cerr << "Error: EVP_DecryptFinal_ex() failed" << endl; fin.close(); fout.close(); EVP_CIPHER_CTX_free(ctx); return -1; } fout.write((char *)outbuf, outlen); // 关闭文件解密上下文 fin.close(); fout.close(); EVP_CIPHER_CTX_free(ctx); return 0; } int main() { const char *key = "0123456789abcdef0123456789abcdef"; const char *iv = "0123456789abcdef"; const char *infile = "input.txt"; const char *outfile = "output.txt"; // 加密 if (aes_encrypt(key, iv, infile, outfile) != 0) { cerr << "Error: Encryption failed" << endl; return -1; } cout << "Encryption succeeded" << endl; // 解密 if (aes_decrypt(key, iv, outfile, "input_decrypted.txt") != 0) { cerr << "Error: Decryption failed" << endl; return -1; } cout << "Decryption succeeded" << endl; return 0; } ``` 这个示例代码中,我们使用了OpenSSL库提供的EVP_aes_256_cbc加密算法,对给定的输入文件进行加密解密。在实际使用中,你需要根据自己的需求修改参数,比如加密算法、密钥、向量、输入文件和输出文件等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值