LoginSignup
27

More than 5 years have passed since last update.

絶対に安全なパスワードを生成したい

Last updated at Posted at 2015-08-14

副題: 128 bit 乱数は意外に短いし扱いやすい

TL;DR

絶対に安全なパスワードを生成するワンライナー

$ ruby -r securerandom -e "puts SecureRandom.urlsafe_base64"

安全なパスワード長

総当たり攻撃に対しては、128 bit あれば 2030 年ごろまでは安全だと言われているようです。

鍵長・アルゴリズムと耐用年数がひと目で分かる便利サイト: http://www.keylength.com/en/

128 bit 乱数

Ruby には暗号論的に大丈夫な乱数を作る SecureRandom モジュールがあります。

出力は base64 でも hex でも binary string でも、デフォルトで 128 bit 乱数を生成してくれるので安心です。

pry > require 'securerandom'

pry > SecureRandom.urlsafe_base64
=> "V0Tthv9uo_KK-4rHvcmeoA"

pry > SecureRandom.hex  
=> "6e02f273b7954e8fe00741ca8d50234a"

pry > SecureRandom.random_bytes
=> "\xEE\vk#\xB9\x04\x9D\xCC\xA7\xB4%\xC7\xAFt\xB6\\"

意外に短くて扱いやすい

128 bit って聞くと長いイメージがあるけど、base64 エンコードなら たった 22 文字 です。

中途半端に 8 文字の乱数で記号混ぜたりするよりもよっぽど扱いやすくて、安心です。

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
27