1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-30 19:12:28 +02:00
Files
archived-doc-ja/reference/strings/functions/crypt.xml
Hideyuki Shimooka 0f9e93d57f translation updated
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@189166 c90b9560-bf6c-de11-be94-00142212c4b1
2005-06-24 15:04:40 +00:00

180 lines
6.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./ja/functions/strings.xml, last change in rev 1.1 -->
<!-- EN-Revision: 1.11 Maintainer: hirokawa Status: ready -->
<!-- CREDITS: shimooka -->
<refentry id="function.crypt">
<refnamediv>
<refname>crypt</refname>
<refpurpose>文字列の一方向の暗号化(ハッシュ化)を行う</refpurpose>
</refnamediv>
<refsect1>
<title>説明</title>
<methodsynopsis>
<type>string</type><methodname>crypt</methodname>
<methodparam><type>string</type><parameter>str</parameter></methodparam>
<methodparam><type>string</type><parameter>
<replaceable><optional>salt</optional></replaceable>
</parameter></methodparam>
</methodsynopsis>
<para>
<function>crypt</function>は、Unix 標準の <abbrev>DES</abbrev>
暗号を使って文字列を暗号化します。引数には暗号化したい文字列を指
定し、オプションで暗号化のベースとなる 2 文字の'salt' 文字列を指
定します。暗号化に関する関数の詳細は Unix man ページを参照してく
ださい。
</para>
<simpara>
salt引数が指定されない場合、この関数をコールするたびに
PHPによりランダムに生成されます。
</simpara>
<simpara>
いくつかのオペレーティングシステムは、複数の暗号化方式をサポート
しています。実際、標準のDES暗号の替わりにMD5に基づく暗号化アルゴ
リズムが使用されることが時々あります。暗号化手法は、salt引数によ
り選定されます。インストール時に、PHPはcrypt関数の機能を定義し、
他の暗号化方式用のsaltを受付ます。saltが指定されない場合、システ
ムのデフォルトの暗号化手法がMD5でない限りPHPはデフォルトで標準の2
文字DES saltを自動的に生成します。暗号化手法がMD5の場合、MD5互換
のsaltが生成されます。PHPは、定数CRYPT_SALT_LENGTH を設定します。
この定数により、標準の2文字のsaltまたはより長い12文字MD5 saltのど
ちらが適用可能であるかを知ることが可能です。
</simpara>
<simpara>
生成されたsaltを使用する場合、saltが生成されるのは一回限りである
ことに気付く必要があります。この関数を繰り返しコールする場合、こ
のことは、出力だけでなく、セキュリティにも影響を与える可能性があ
ります。
</simpara>
<simpara>
標準DES暗号<function>crypt</function>は、出力の最初の2文字をsalt
として使用します。
<parameter>str</parameter>の最初の8文字を使用するだけです。
このため、(同じsaltを使用した場合、)同じ8文字から始まるより長い文
字列について同じ結果が生成されます。
</simpara>
<simpara>
crypt() 関数が複数の暗号化手法をサポートするシステムにおいては、
指定した型を利用可能であるかにより、次の定数を0又は1に設定します。
</simpara>
<itemizedlist>
<listitem>
<simpara>
CRYPT_STD_DES - 2文字 SALT の標準 DES 暗号
</simpara>
</listitem>
<listitem>
<simpara>
CRYPT_EXT_DES - 9文字の拡張DES暗号
</simpara>
</listitem>
<listitem>
<simpara>
CRYPT_MD5 - $1$ で始まる12文字のSALTを有するMD5暗号
</simpara>
</listitem>
<listitem>
<simpara>
CRYPT_BLOWFISH - $2$ もしくは $2a$ で始まる16文字の拡張DES暗号
</simpara>
</listitem>
</itemizedlist>
<note>
<simpara>
<function>crypt</function> は単方向アルゴリズムを使用している
ため、復号化するための関数 (decrypt) はありません。
</simpara>
</note>
<example>
<title><function>crypt</function>の例</title>
<programlisting role="php">
<![CDATA[
<?php
$password = crypt("My1sTpassword"); // saltを自動的に生成
/* 異なったハッシュアルゴリズムが使用された際の問題を避けるために
crypt()の結果全体をパスワード比較用のsaltとして渡す必要があります。
(上記のように標準DESに基づくパスワードハッシュは2文字のsaltを使用します
が、MD5に基づくハッシュは12文字のsaltを使用します) */
if (crypt($user_input, $password) == $password) {
echo "Password verified!";
}
?>
]]>
</programlisting>
</example>
<example>
<title>Using <function>crypt</function> with htpasswd</title>
<programlisting role="php">
<![CDATA[
<?php
// Set the password
$password = 'mypassword';
// Get the hash, letting the salt be automatically generated
$hash = crypt($password);
?>
]]>
</programlisting>
</example>
<example>
<title>異なる暗号化手法を用いた <function>crypt</function> の例</title>
<programlisting role="php">
<![CDATA[
<?php
if (CRYPT_STD_DES == 1) {
echo 'Standard DES: ' . crypt('rasmuslerdorf', 'rl') . "\n";
}
if (CRYPT_EXT_DES == 1) {
echo 'Extended DES: ' . crypt('rasmuslerdorf', '_J9..rasm') . "\n";
}
if (CRYPT_MD5 == 1) {
echo 'MD5: ' . crypt('rasmuslerdorf', '$1$rasmusle$') . "\n";
}
if (CRYPT_BLOWFISH == 1) {
echo 'Blowfish: ' . crypt('rasmuslerdorf', '$2a$07$rasmuslerd...........$') . "\n";
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Standard DES: rl.3StKT.4T8M
Extended DES: _J9..rasmBYk8r9AiWNc
MD5: $1$rasmusle$rISCgZzpwk3UhDidwXvin0
Blowfish: $2a$07$rasmuslerd............nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra
]]>
</screen>
</example>
<simpara>
<function>md5</function>および<link linkend="ref.mcrypt">mcrypt拡
張モジュール</link>も参照ください。
</simpara>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->