@kyanny's blog

My thoughts, my life. Views/opinions are my own.

openssl rand

ランダムな文字列を得る。Ruby の securerandom を使うより手っ取り早い。

❯ openssl rand -hex 16
338c7e891489549adbe61fdf462e6a52

❯ openssl rand -base64 16
Nce/bRRIEO2dcYDOeJ51OA==

が、urlsafe base64 は作れない。

openssl randbase64 にパイプしてもいい。

❯ openssl rand 16 | /usr/bin/base64
g0FffgJX3x3xjnNuQPcrlA==

❯ openssl rand 16 | /usr/local/bin/base64
SeYrVtiCEgt6BwWhAq1/vw==

が、やはり urlsafe base64 は作れない。