Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with decrypting data using aes-256-gcm and encryptor version 1.3.0 #34

Open
HIMANSHU-ELIGIBLE opened this issue Sep 24, 2019 · 2 comments

Comments

@HIMANSHU-ELIGIBLE
Copy link

HIMANSHU-ELIGIBLE commented Sep 24, 2019

Hi Team,

We use aes-256-gcm and pass it to encrypt and decrypt function to override default algorithm. However, recently due to a bug we switched back to encryptor version. 1.3.0 and encrypted some data using the encryption logic. encryption didn't raise an error however, I am not able to decrypt the same data now. Can you please suggest if "aes-256-gcm" is supported by encryptor v1.3.0 and that if there is any way to decrypt data encrypted using "aes-256-gcm" algorithm and encryptor version. 1.3.0.

Thank you, Attaching a reproducible test case (ruby code) here if that helps -

require 'base64'
require 'encryptor'

def algorithm
  'aes-256-gcm'
end

data_key = "123456789101112"

def cipher
  OpenSSL::Cipher.new(algorithm).tap do |cipher|
    # Required before '#random_key' or '#random_iv' can be called.
    # http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL/Cipher.html#method-i-encrypt
    cipher.encrypt
  end
end

iv = cipher.random_iv
salt = SecureRandom.random_bytes(64)
encrypted_content   = Encryptor.encrypt("himanshu", { key: data_key, iv: iv, salt: salt, algorithm: algorithm })

truncated_iv = iv.size > cipher.iv_len ? iv[0, cipher.iv_len] : iv
Encryptor.decrypt(encrypted_content, { key: data_key, iv: truncated_iv, salt: salt, algorithm: algorithm })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants