跨平台的加解密方案


缘起:

在Linux上加密文件,传送到百度云上,然后再从百度云上下载文件;但是之前用的ccrypt命令在Windows上没有一个比较好的图形化/终端解密方案。

搜索关键字:
  • encrypt file on linux and decrypt on windows
  • use password when tar
参考解答:

用gpg或aes是比较靠谱和方便的;除了在Linux上加密方便之外,在Windows上也有经过验证的GUI软件提供解密,挺好的。

参考链接:

==

因为需要用脚本自动加密传输的附件,确定的加解密方案为gpg,在Linux系统上只要装了gpg的话,不论是加密还是解密都很简单,但我这里需要的是从文件中读取字符串作为密钥进行对称加密,所以查看了一下gpg的manual手册,在网上搜索了之后自己进行测试,得到实际经验如下:

# gpg --dump-options | grep pass
--passphrase
--passphrase-fd
--passphrase-file
--passphrase-repeat

但是我使用其中的 –passphrase-file 选项时,还会提示需要继续输入密码(系统环境为:Ubuntu 14.04.2 LTS i686)

http://unix.stackexchange.com/questions/60213/gpg-asks-for-password-even-with-passphrase

=-=

I am in your exact same boat (it worked on Fedora but not Ubuntu). Here is an apparent work around I discovered:

echo your_password | gpg –passphrase-fd 0 your_file.gpg

Explanation: Passing 0 causes –passphrase-fd to read from STDIN rather than from a file. So, piping the passphrase will get –passphrase-fd to accept your specified password string.

=-=

所以最后退而求其次用的是 “–passphrase-fd 0” 这个方法替代(直接将密码文件的内容cat出来,然后管道传下去,效果和手动输入是一样的)

Ps:我测试了 –passphrase-file 和 –batch –no-tty –yes 都不行。

cat $passphrase | gpg --passphrase-fd 0 -c ${bak_path}/bak_${date_yyyymmdd}.zip
#若命令正确执行,则会返回0,同时生成文件${bak_path}/bak_${date_yyyymmdd}.zip.pgg

直接使用上面的命令,或是手动执行包含该命令的脚本是可以正常执行的,但是,放入crontab之后就会报错:

gpg: cannot open tty `/dev/tty’: No such device or address

去网上搜索了之后发现有不少人也遇到了这个问题,原因什么的就不深究了,说下解决办法吧:

增加”–no-tty”和”–batch”选项

cat $passphrase | gpg --no-tty --batch --passphrase-fd 0 -c ${bak_path}/bak_${date_str}.zip

==

bpcs_uploader的使用
搜索关键字:
  • vps baidu.com api
参考链接:

=EOF=


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注