我怎么能隐藏/保护Perl脚本的密码

我正在编写一个Perl脚本,需要连接到SMTP服务器才能发送邮件,但我真的不喜欢这样的事情:
my $pass = '123456';

我找到了Data :: Encrypted,它应该允许用户第一次提示它然后加密存储它.

use Data::Encrypted file => ".passwd",qw(encrypted);
my $password = encrypted('password');

但我无法使其工作,它会导致运行时错误

Bad key file format at /Library/Perl/5.12/Data/Encrypted.pm line 78

有人有同样的问题,或者知道隐藏/保护密码的其他方法吗?

解决方法

Data::Encrypted模块最后一次发布于2001年.我想说这是一个不使用它的好兆头.

通常情况下,我认为存储密码甚至是加密的坏主意.但是,如果您必须存储密码以便与另一个系统联系使用,则可以对其进行加密.我这样做的方式是这样的:

# Rijndael is also kNown as AES,which is the encryption standard used by the NSA
use Crypt::Rijndael;
use IO::Prompter;

# This secret is exactly 32 bytes long,you Could prompt for this as a
# passphrase or something and pad it with spaces or whatever you need
my $app_secret = 'this_is_the_key_the_app_uses....';

# Setup the encryption system
my $crypto = Crypt::Rijndael->new( $app_secret,Crypt::Rijndael::MODE_CBC() );

# Ask the user to enter the password the first time
my $password = prompt "password: ",-echo => ''; # from IO::Prompter

# Encrypt the password. You can save this off into a file however you need to
my $enc_password = $crypto->encrypt($password);

# Later load it from the file and decrypt it:
my $password = $crypto->decrypt($password);

有关更多信息,请参阅Crypt::RijndaelIO::Prompter.

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...