Ruby - unsupported encryption algorithm (AES-256-GCM)

I get an error message:

unsupported encryption algorithm (AES-256-GCM) (RuntimeError)

But I have all the requirements:

Ruby version:

$ ruby ​​--version

ruby 2.1.2p95

OpenSSL makes a gcm list:

$ openssl enc -help 2> & 1 | grep gcm

-aes-128-ecb -aes-128-gcm -aes-128-ofb
-aes-192-ecb -aes-192-gcm -aes-192-ofb
-aes-256-ecb -aes-256-gcm -aes-256-ofb

Ruby interpreter:

$ irb

2.1.2: 001> requires "openssl"; puts OpenSSL :: VERSION

1.1.0

=> nil

2.1.2: 002> OpenSSL :: Cipher.ciphers.include? AES-128-GCM

=> true

And still I get errors while executing this code :

2.1.2 :001 > require 'openssl' => true 2.1.2 :002 > cipher = OpenSSL::Cipher::AES.new(128, :GCM) RuntimeError: unsupported cipher algorithm (AES-128-GCM) from /home/m/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/openssl/cipher.rb:27:in `initialize' from /home/m/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/openssl/cipher.rb:27:in `block (3 levels) in <class:Cipher>' from (irb):2:in `new' from (irb):2 from /home/m/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>' 

How do I get GCM to work in ruby?

+6
source share
1 answer

What works for me

 OpenSSL::Cipher.new('aes-128-gcm') 

I am not sure why you are getting an error message with your approach.

Edit:

This may be an upper / lower case problem. This may be an actual error.

The following works:

 OpenSSL::Cipher::AES.new(128, :CBC) 

because we find "AES-128-CBC" (all upper case) in OpenSSL::Cipher::AES.ciphers . AES.new seems to be searching for its ciphers with uppercase characters.

So the following does not work:

 OpenSSL::Cipher::AES.new(128, :GCM) 

because it is "aes-128-gcm" in the list of ciphers.

+5
source

Source: https://habr.com/ru/post/971890/


All Articles