I want do these
require "openssl"
decipher = OpenSSL::Cipher::Cipher.new('des3')
decipher.decrypt
decipher.key = "11111111"
But it throws OpenSSL::Cipher::CipherError: key length too short
I have tried to set the key length by des.key_len = 8
, it throws OpenSSL::Cipher::CipherError: invalid key length
error.
From the OpenSSL ruby documentation:
key_length = integer → integer
Sets the key length of the cipher. If the cipher is a fixed length cipher then attempting to set the key length to any value other than the fixed value is an error.
Under normal circumstances you do not need to call this method (and probably shouldn’t).
See EVP_CIPHER_CTX_set_key_length for further information.
And as Triple Des is a cipher with fixed key length (168-bit ~ 24-bytes), you get an error.