0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Perl で ハッシュ値を生成する

Last updated at Posted at 2023-01-04

Perlの標準モジュールには、ハッシュ値を生成するモジュールは存在しないので、CPAN(Comprehensive Perl Archive Network)からハッシュ値を生成するモジュールをインストールします。

尚、Windows版のPerlである、Strawberry Perl for Windows では、Strawberry Perl for Windowsをインストールした時にハッシュ値を生成するモジュールもインストールされているため、追加でインストールする必要はありません。

SHA系ハッシュアルゴリズムのモジュールのインストール (Linux系)

Digest::SHAモジュールには、SHA系ハッシュアルゴリズムを生成する関数が提供されています。

以下のコマンドでDigest::SHAモジュールをインストールします。

# sudo cpan Digest::SHA

SHA1, SHA256アルゴリズムでハッシュ値を生成し、出力するプログラムです。

use Digest::SHA qw(sha1 sha1_hex sha1_base64);
use Digest::SHA qw(sha256 sha256_hex sha256_base64);

my $digest1 = sha1_hex('Hello World');
my $digest2 = sha256_hex('Hello World');

print "SHA1\n";
print $digest1;
print "\n";
print "SHA256\n";
print $digest2;
print "\n";

参考情報

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?