加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 21:54:37 所属栏目:大数据 来源:网络整理
导读:我正在编写一个Perl脚本,需要连接到SMTP服务器才能发送邮件,但我真的不喜欢这样的事情: my $pass = '123456'; 我找到了Data :: Encrypted,它应该允许用户第一次提示它然后加密存储它. use Data::Encrypted file = ".passwd",qw(encrypted);my $password = e
我正在编写一个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::Rijndael和IO::Prompter.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读