我覺得pack
& unpack
很可能會更有效:
use Digest::SHA;
my $digest = Digest::SHA->new('sha1')->add('hello')->digest;
my @ints = unpack('N*', $digest);
print "@ints\n";
my $redone = pack('N*', @ints);
print "match\n" if $digest eq $redone;
my $hexdigest = sprintf '%08x' x @ints, @ints;
print "$hexdigest\n";
printf "%s\n", Digest::SHA->new('sha1')->add('hello')->hexdigest;
use MIME::Base64 'encode_base64';
my $b64digest = encode_base64(pack('N*', @ints));
print $b64digest;
printf "%s\n", Digest::SHA->new('sha1')->add('hello')->b64digest;
輸出:
2868168221 3703957666 3669941775 994585817 2930328397
match
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
qvTGHdzF6KLavt4PO0gs2a6pQ00=
qvTGHdzF6KLavt4PO0gs2a6pQ00
請注意,MIME::Base64
填充結果,並且b64digest
方法沒有。但是如果需要的話,很容易就可以去掉尾隨的=
。
來源
2010-08-06 05:48:33
cjm
類似解決方案我已經破解了(雖然可能因地圖而更好)可以顛倒嗎?通過顛倒我的意思是我可以把它從整數,並得到它的base64編碼(這是相同的摘要base64編碼),如果我想? – xenoterracide 2010-08-06 04:55:54