Module: Gitlab::CryptoHelper

Extended by:
CryptoHelper
Included in:
CryptoHelper
Defined in:
lib/gitlab/crypto_helper.rb

Constant Summary collapse

AES256_GCM_OPTIONS =
{
  algorithm: 'aes-256-gcm',
  key: Settings.attr_encrypted_db_key_base_32,
  iv: Settings.attr_encrypted_db_key_base_12
}.freeze

Instance Method Summary collapse

Instance Method Details

#aes256_gcm_decrypt(value) ⇒ Object


23
24
25
26
27
28
# File 'lib/gitlab/crypto_helper.rb', line 23

def aes256_gcm_decrypt(value)
  return unless value

  encrypted_token = Base64.decode64(value)
  Encryptor.decrypt(AES256_GCM_OPTIONS.merge(value: encrypted_token))
end

#aes256_gcm_encrypt(value) ⇒ Object


18
19
20
21
# File 'lib/gitlab/crypto_helper.rb', line 18

def aes256_gcm_encrypt(value)
  encrypted_token = Encryptor.encrypt(AES256_GCM_OPTIONS.merge(value: value))
  Base64.strict_encode64(encrypted_token)
end

#sha256(value) ⇒ Object


13
14
15
16
# File 'lib/gitlab/crypto_helper.rb', line 13

def sha256(value)
  salt = Settings.attr_encrypted_db_key_base_truncated
  ::Digest::SHA256.base64digest("#{value}#{salt}")
end