Skip to content

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

@HIMANSHU-ELIGIBLE

Description

@HIMANSHU-ELIGIBLE

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 })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions