#include <iostream> #include <string> #include <stdlib.h> using namespace std; int main(int argc,char *argv[]) { string cmd = "openssl "; for(int i = 1; i<argc; i++) { cmd +=" "; cmd += argv[i]; } cout << cmd<<endl; cmd +=" "; cmd +="-k 123"; //指定加密的密码。 system(cmd.c_str()); }
ubuntu@ubuntu-vm:~/workspace/encryption$ g++ main.cpp
ubuntu@ubuntu-vm:~/workspace/encryption$ ./a.out enc -des -e -a -in main.cpp -out aa
ubuntu@ubuntu-vm:~/workspace/encryption$ ./a.out enc -des -d -a -in aa
openssl enc -des -d -a -in aa
-----------
openssl也可以进行文件的加密。
把加密的文件传给需要的人后,只要他知道加密方式和加密口令,就可以解密查看文件。
openssl支持的加密算法很多,包括:bf,cast,des,des3,idea,rc2,rc5等及以上各种的变体,具体可参阅相关文档。
1.加密一个文件:
[root@fxvsystem root]# openssl enc -des -e -a -in install.log -out install.log.des
enter des-cbc encryption password:
Verifying – enter des-cbc encryption password:
输入密码之后,就会生成install.log.des文件,这个文件名是自己指定的,可以随意写。
其中:
enc表明你打算使用某个算法
-des是具体使用的某个算法
-e 表明要加密
-a 同样是使用ASCII进行编码
-in 要加密的文件名字
-out 加密后的文件名字
把生成的文件传到另一台机器后,执行如下命令进行解密
[root@fxvsystem gpg]# openssl enc -des -d -a -in install.log.des -out install.log
enter des-cbc decryption password:
输入口令后,就可以得到解密后的文件了。
其中
-d表明要进行解密
原文链接: https://www.cnblogs.com/yuguangyuan/p/7777618.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/397804
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!