Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
OpenSSL::Cipher#random_key
() -> ::String
cipher.random_key → key
ext/openssl/lib/openssl/cipher.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/ext/openssl/lib/openssl/cipher.rb, line 43
def random_key
str = OpenSSL::Random.random_bytes(self.key_len)
self.key = str
end
Generate a random key with OpenSSL::Random.random_bytes and sets it to the cipher, and returns it.
You must call encrypt or decrypt before calling this method.