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

Ben*_*ldt 7 encryption passwords perl

我正在编写一个需要连接到SMTP服务器才能发送邮件的Perl脚本,但我真的不喜欢这样的东西:

my $pass = '123456';
Run Code Online (Sandbox Code Playgroud)

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

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

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

/Library/Perl/5.12/Data/Encrypted.pm第78行的密钥文件格式错误

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

zos*_*tay 10

数据加密::模块于去年发布的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);
Run Code Online (Sandbox Code Playgroud)

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