Method: OpenSSL::Cipher#initialize

Defined in:
ext/openssl/ossl_cipher.c

#new(string) ⇒ Object

The string must contain a valid cipher name like “aes-256-cbc”.

A list of cipher names is available by calling OpenSSL::Cipher.ciphers.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'ext/openssl/ossl_cipher.c', line 111

static VALUE
ossl_cipher_initialize(VALUE self, VALUE str)
{
    EVP_CIPHER_CTX *ctx;
    const EVP_CIPHER *cipher;
    char *name;

    name = StringValueCStr(str);
    GetCipherInit(self, ctx);
    if (ctx) {
  ossl_raise(rb_eRuntimeError, "Cipher already initialized!");
    }
    AllocCipher(self, ctx);
    if (!(cipher = EVP_get_cipherbyname(name))) {
  ossl_raise(rb_eRuntimeError, "unsupported cipher algorithm (%"PRIsVALUE")", str);
    }
    if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, -1) != 1)
  ossl_raise(eCipherError, NULL);

    return self;
}