微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我怎么能隐藏/保护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.

原文地址:https://www.jb51.cc/Perl/171908.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐