信息时代,密码会很多, 有些很少用,过些时间就会忘掉。 是件比较痛苦的事情
于是想到一个方法,用于集中管理密码,只要记住一个就可以了,
加密方法如下:
1、建立一个passworddb.txt,将需要加密的密码保存到里面 (实际使用的时候不用起这么明显的名字-_-)
2、使用base64进行编码
3、对第二步的输出进行triple-des加密
4、对第三步的输出进行base64编码,输出passworddb.txt.bdb
解密就是逆过程,方法如下:
1、对加密文件passworddb.txt.bdb进行base64解码
2、对第一步的输出进行triple-des解密
3、对第二步的输出进行base64解码,输出passworddb.txt
加密的东东,当然使用openssl了,很好很强大。 但是要是一个个的敲入命令, 不是很方便,于是我写了一个批处理,用于加解密。 哈哈, 这下可以将加密之后的密码文件放到邮箱了, 只要记住加密这个文件的秘钥即可, 以前的密码记不得的时解开看一下, 很方便!
批处理文件(ed.bat)代码如下:
- @rem /* decrypt file with openssl. */
- @echo off
- @rem /* check parameters */
- @setlocal EnableDelayedExpansion
- if {%1}== {} goto help
- if {%2}== {} goto help
- if {%3}== {} goto help
- set ENCKEY=%3
- set FILEINPUT=%2
- @rem /* calculate output file name. */
- @rem /* if output file name is specified by the command parameter then it will be used. */
- @rem /* otherwise to append/remove .bdb extension to/from the input file name */
- set FILEOUTPUT=%2
- if not {%4} == {} (set FILEOUTPUT=%4) else (
- set EXT=%FILEOUTPUT:~-4%
- if "!EXT!"==".bdb" (
- set FILEOUTPUT=%FILEOUTPUT:.bdb=%
- ) else (
- set FILEOUTPUT=%FILEOUTPUT%.bdb
- )
- )
- set FILE1=%FILEOUTPUT%.b
- set FILE2=%FILEOUTPUT%.bd
- @rem /* Find weather specified file exsits! */
- if exist %FILEOUTPUT% (
- echo "%FILEOUTPUT% Exists. overwrite it? (y/n)"
- set /P Query=
- if "!Query!" == "n" goto end
- )
- if exist %FILE1% (
- echo "%FILE1% Exists. overwrite it? (y/n)"
- set /P Query=
- if "!Query!" == "n" goto end
- )
- if exist %FILE2% (
- echo "%FILE2% Exists. overwrite it? (y/n)"
- set /P Query=
- if "!Query!" == "n" goto end
- )
- if %1 == enc goto encrypt-base64-des3-base64
- if %1 == dec goto decrypt-base64-des3-base64
- goto help
- @rem /* encrypt file with base64 des3 base64 algorithm: %FILEINPUT%->%FILE1%->%FILE2%->%FILEOUTPUT% */
- :encrypt-base64-des3-base64
- call openssl base64 -in %FILEINPUT% -out %FILE1%
- if errorlevel 1 goto error
- call openssl des3 -salt -k %ENCKEY% -in %FILE1% -out %FILE2%
- if errorlevel 1 goto error
- call openssl base64 -in %FILE2% -out %FILEOUTPUT%
- if errorlevel 1 goto error
- echo File encrypted to %FILEOUTPUT% successfully!
- goto end
- @rem /* decrypt file with base64 des3 base64 algorithm: %FILEINPUT%->%FILE1%->%FILE2%->%FILEOUTPUT% */
- :decrypt-base64-des3-base64
- call openssl base64 -d -in %FILEINPUT% -out %FILE1%
- if errorlevel 1 goto error
- call openssl des3 -d -salt -k %ENCKEY% -in %FILE1% -out %FILE2%
- if errorlevel 1 goto error
- call openssl base64 -d -in %FILE2% -out %FILEOUTPUT%
- if errorlevel 1 goto error
- echo File decrypted to %FILEOUTPUT% successfully!
- goto end
- :error
- echo error!
- goto :end
- :help
- echo decrypt file: dec file password [outfile]
- echo encrypt file: enc file password [outfile]
- :end
- if exist %FILE1% del %FILE1%
- if exist %FILE2% del %FILE2%
使用方法:
加密 passworddb.txt,密码是123456 (方法1默认将加密文件保存为passworddb.txt.bdb,方法二明确指定加密后文件保存为password.enc)
1、ed enc passworddb.txt 123456
2、ed enc passworddb.txt 123456 password.enc
解密(方法1解密后,保存为passworddb.txt,方法二明确指定解密后保存为password.txt)
1、 ed dec passworddb.txt.bdb 123456
2、 ed dec passworddb.txt.bdb 123456 password.txt
注: 本想将openssl相关程序和批处理文件上传上来,但是csdn不支持-_-!
openssl可以到www.openssl.org去下载源码编译,如有需要也可以给我留言, 留下邮箱, 我会发一份给你。