Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

OpenSSL::Cipher#key=

cipher.key = string → string

Sets the cipher key. To generate a key, you should either use a secure random byte string or, if the key is to be derived from a password, you should rely on PBKDF2 functionality provided by OpenSSL::PKCS5. To generate a secure random-based key, Cipher#random_key may be used.

Only call this method after calling Cipher#encrypt or Cipher#decrypt.

See also #iv_len= #key_len #iv_len #key_len= also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0