perl-5.38.0
crypt PLAINTEXT,SALT

Creates a digest string exactly like the crypt(3) function in the C library (assuming that you actually have a version there that has not been extirpated as a potential munition).

C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を 作成します(一時的な必需品として、まだ絶滅していないバージョンを 持っていると仮定しています)。

crypt is a one-way hash function. The PLAINTEXT and SALT are turned into a short string, called a digest, which is returned. The same PLAINTEXT and SALT will always return the same string, but there is no (known) way to get the original PLAINTEXT from the hash. Small changes in the PLAINTEXT or SALT will result in large changes in the digest.

crypt は一方向ハッシュ関数です。 PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、 それが返されます。 PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから 元の PLAINTEXT を得る(既知の)方法はありません。 PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。

There is no decrypt function. This function isn't all that useful for cryptography (for that, look for Crypt modules on your nearby CPAN mirror) and the name "crypt" is a bit of a misnomer. Instead it is primarily used to check if two pieces of text are the same without having to transmit or store the text itself. An example is checking if a correct password is given. The digest of the password is stored, not the password itself. The user types in a password that is crypt'd with the same salt as the stored digest. If the two digests match, the password is correct.

復号化関数はありません。 この関数は暗号化のためにはまったく役に立ちません(このためには、 お近くの CPAN ミラーで Crypt モジュールを探してください)ので、 "crypt" という名前は少し間違った名前です。 その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを 転送したり保管したりせずにチェックするために使います。 例としては、正しいパスワードが与えられたかどうかをチェックがあります。 パスワード自身ではなく、パスワードのダイジェストが保管されます。 ユーザーがパスワードを入力すると、保管されているダイジェストと同じ salt で crypt します。 二つのダイジェストが同じなら、パスワードは正しいです。

When verifying an existing digest string you should use the digest as the salt (like crypt($plain, $digest) eq $digest). The SALT used to create the digest is visible as part of the digest. This ensures crypt will hash the new string with the same salt as the digest. This allows your code to work with the standard crypt and with more exotic implementations. In other words, assume nothing about the returned string itself nor about how many bytes of SALT may matter.

すでにあるダイジェスト文字列を検証するには、ダイジェストを (crypt($plain, $digest) eq $digest のようにして)salt として使います。 ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。 これにより、crypt は同じ salt で新しい文字列を ダイジェストとしてハッシュ化できるようにします。 これによって標準的な crypt や、より風変わりな 実装でも動作します。 言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、 どのような仮定もしてはいけません。

Traditionally the result is a string of 13 bytes: two first bytes of the salt, followed by 11 bytes from the set [./0-9A-Za-z], and only the first eight bytes of PLAINTEXT mattered. But alternative hashing schemes (like MD5), higher level security schemes (like C2), and implementations on non-Unix platforms may produce different strings.

伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて 集合 [./0-9A-Za-z] からの 11 バイトで、PLAINTEXT の最初の 8 バイトだけが意味があります。 しかし、(MD5 のように) 異なったハッシュ手法、 (C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの 実装などでは異なった文字列が生成されることがあります。

When choosing a new salt create a random two character string whose characters come from the set [./0-9A-Za-z] (like join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]). This set of characters is just a recommendation; the characters allowed in the salt depend solely on your system's crypt library, and Perl can't restrict what salts crypt accepts.

新しい salt を選択する場合は、集合 [./0-9A-Za-z] から (join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64] の ようにして)ランダムに2 つの文字を選びます。 この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化 ライブラリだけに依存し、Perl は crypt が どのような salt を受け付けるかについて制限しません。

Here's an example that makes sure that whoever runs this program knows their password:

プログラムを実行する人が、 自分のパスワードを知っていることを確認する例です:

    my $pwd = (getpwuid($<))[1];

    system "stty -echo";
    print "Password: ";
    chomp(my $word = <STDIN>);
    print "\n";
    system "stty echo";

    if (crypt($word, $pwd) ne $pwd) {
        die "Sorry...\n";
    } else {
        print "ok\n";
    }

Of course, typing in your own password to whoever asks you for it is unwise.

もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。

The crypt function is unsuitable for hashing large quantities of data, not least of all because you can't get the information back. Look at the Digest module for more robust algorithms.

crypt 関数は大量のデータのハッシュ化には 向いていません; これは情報を戻せないという理由だけではありません。 より頑強なアルゴリズムについては Digest モジュールを参照してください。

If using crypt on a Unicode string (which potentially has characters with codepoints above 255), Perl tries to make sense of the situation by trying to downgrade (a copy of) the string back to an eight-bit byte string before calling crypt (on that copy). If that works, good. If not, crypt dies with Wide character in crypt.

Unicode 文字列(潜在的には 255 を越えるコードポイントを持つ文字を 含みます)に crypt を使った場合、Perl は crypt を呼び出す前に与えられた 文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る) ことで状況のつじつまを合わせようとします。 うまく動けば、それでよし。 動かなければ、cryptWide character in crypt という メッセージと共に die します。

Portability issues: "crypt" in perlport.

移植性の問題: "crypt" in perlport