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.

phpでパスワードの単純な暗号化とハッシュ化をしてみた

Last updated at Posted at 2022-09-14

 phpで、パスワードの単純な暗号化とハッシュ化をしてみた

public function passwordHash($password)
{
    $pass = 'password';
    $iv = '1234567890123456'; //16桁

    // 暗号化
    $password = openssl_encrypt(
        $password,
        'aes-256-cbc',
        $pass,
        OPENSSL_RAW_DATA,
        $iv
    );

    // Hash.
    return hash_hmac('sha256', $password, 'secret', false);
}

 $passwordで設定したパスワードを復号化可能な暗号で変身させハッシュ化している

 復号化出来る暗号は、パスワードと対になるランダムなデータに見えるデータで、理論上、データ単位での衝突は無いと思うので暗号化でパスワードを「変身」させ、それをハッシュ化してみた

 それぞれのパラメーターは変更可能です

後々、自分で使うと思うのでメモ。以上です

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?