Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

OpenSSL::Cipher#key=

(::String key) -> ::String
cipher.key = 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 the man page EVP_CipherInit_ex(3).

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