Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
OpenSSL::Cipher.new
(::String cipher_name) -> ::OpenSSL::Cipher
Cipher.new(string) → cipher
ext/openssl/ossl_cipher.c
View on GitHub ↗
static VALUE
ossl_cipher_initialize(VALUE self, VALUE str)
{
EVP_CIPHER_CTX *ctx;
const EVP_CIPHER *cipher;
VALUE cipher_holder;
ossl_want_uninitialized(self, &ossl_cipher_type);
cipher = ossl_evp_cipher_fetch(str, &cipher_holder);
AllocCipher(self, ctx);
if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, -1) != 1)
ossl_raise(eCipherError, "EVP_CipherInit_ex");
rb_ivar_set(self, id_cipher_holder, cipher_holder);
return self;
}
The string must contain a valid cipher name like “aes-256-cbc”.
A list of cipher names is available by calling OpenSSL::Cipher.ciphers.