Encryption of Data in Ruby
Ruby relies on two known libraries to encrypt and decrypt data: gibberish and ezcrypto. Let’s take a look at two implementations in order to figure out how they are both different from each other.
First method of encryption
require ‘gibberish’
text = “text to be encrypted”
aes_key = Gibberish::AES.new(“My Key”)
aes_cypher = aes_key.enc(text)
aes_key.dec(aes_cypher)
Second method of encryption
require ‘ezcrypto’
text = “text to be encrypted”
ez_key = EzCrypto::Key.with_password ‘My key’, ‘My Salt’
ez_cypher = ez_key.encrypt(text)
ez_key.decrypt(text)
It is important to note that both of these libraries required to have underlining library such as C OpenSSL.
Gibberish library can encrypt and decrypt files by accepting file path, so it is useful for working with files.