Digest-Perl-MD5-1.5 > Digest::Perl::MD5

名前

Digest::Perl::MD5 - Ron RivestsのMD5アルゴリズムのPerlによる実装

※訳注: オリジナルのドキュメントでは、Digest::MD5::Perl となっていますが、誤りなので翻訳で修正しています。

責任放棄(=DISCLAIMER)

これはMD5の(Digest::MD5のような)インターフェースではなく、Perlによる実装です。 これはperlだけで書かれており、そのため速くはありませんが、Cのコードなしに動きます。 もし利用できるのであれば、このモジュールの代わりにDigest::MD5を使うべきです。 このモジュールは以下のような場合にのみ有効です

  • (e.g. Cコンパイラがないなど)Digest::MD5 をインストールすることができないコンピュータ

  • 少量の(百万バイト未満)データだけを暗号化する場合。私はパスーワードをハッシュする のに使っています。

  • 教育的な目的

概要

※訳注: 以下のコードはオリジナルのドキュメントでは、Digest::Perl::MD5 となっているところは、Digest::MD5 と書かれています誤りなので、翻訳で修正しています。

 # 関数形式
 use Digest::Perl::MD5  qw(md5 md5_hex md5_base64);

 $hash = md5 $data;
 $hash = md5_hex $data;
 $hash = md5_base64 $data;
    

 # OO形式
 use Digest::Perl::MD5;

 $ctx = Digest::Perl::MD5->new;

 $ctx->add($data);
 $ctx->addfile(*FILE);

 $digest = $ctx->digest;
 $digest = $ctx->hexdigest;
 $digest = $ctx->b64digest;

説明

このモジュールは、これよりもはるかに速いDigest::MD5と同じインタフェースを 持っています。そのため簡単に入れ替えることができます。例えば。

    BEGIN {
      eval {
        require Digest::MD5;
        import Digest::MD5 'md5_hex'
      };
      if ($@) { # ups, no Digest::MD5
        require Digest::Perl::MD5;
        import Digest::Perl::MD5 'md5_hex'
      }     
    }

もしDigest::MD5モジュールが利用できるのであれば、そちらを使い、 なければ、Digest::Perl::MD5を取ればいいでしょう。

Digest::Perl::MD5とあわせてDigest::MD5のPerl部分をインストールし、 通常通りDigest::MD5を使うことも出来ます。そのオブジェクトファイルを ロードすることができなければDigest::Perl::MD5に戻ります。

さらに詳細なドキュメントについては、Digest::MD5モジュールを ご覧ください。

このライブラリを利用する最も簡単な方法は、md5_hex()関数 (あるいはその類)をインポートすることです:

    use Digest::Perl::MD5 'md5_hex';
    print 'Digest is ', md5_hex('foobarbaz'), "\n";

その実装が正しく動作するように規定されていれば、上記の例は 以下のメッセージを出力します

    Digest is 6df23dc03f9b54cc38a0fc1483df6e21

同じチェックサムをOO形式で計算することもできます:

    use Digest::MD5;
    
    $md5 = Digest::MD5->new;
    $md5->add('foo', 'bar');
    $md5->add('baz');
    $digest = $md5->hexdigest;
    
    print "Digest is $digest\n";

制約

このMD5アルゴリズムの実装には、いくつかの制約があります:

  • 遅い、とても遅いです。私は出来うる限りを尽くしました。しかしそれでもDigest::MD5のほうが約135倍 速いのです。容認できる時間内には百万バイトまでのデータしか暗号化することはできません。 しかしパスワードのような少量のデータを暗号化するためには非常に便利です。

  • 32ビットアーキテクチャでは2^32 ビット = 512 MBまでしか暗号化することができません。 そのような量のデータにはDigest::MD5を使うべきです。

  • Digest::Perl::MD5は暗号化するデータを全てメモリにロードします。 これは今後の課題(=todo)になっています。

参考資料

Digest::MD5

md5sum(1)

RFC 1321

著作権(=COPYRIGHT)

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

 Copyright 2000 Christian Lackas, Imperia Software Solutions
 Copyright 1998-1999 Gisle Aas.
 Copyright 1995-1996 Neil Winton.
 Copyright 1991-1992 RSA Data Security, Inc.

The MD5 algorithm is defined in RFC 1321. The basic C code implementing the algorithm is derived from that in the RFC and is covered by the following copyright:

  • Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved.

    License to copy and use this software is granted provided that it is identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing this software or this function.

    License is also granted to make and use derivative works provided that such works are identified as "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing the derived work.

    RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind.

    These notices must be retained in any copies of any part of this documentation and/or software.

This copyright does not prohibit distribution of any version of Perl containing this extension under the terms of the GNU or Artistic licenses.

作者(=AUTHORS)

オリジナルのMD5インターフェースはNeil Winton(N.Winton@axion.bt.co.uk)に よって書かれました。

Digest::MD5はGisle Aas <gisle@aas.no>によって作成されました。 (私は彼のインタフェースとドキュメントの一部をとっています)

'use integer'というヒントに対してGuido Flohrに感謝します。

このリリースはChristian Lackas <delta@clackas.de>によって作成されました。

翻訳者

川合孝典 (GCD00051@nifty.ne.jp)