mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
26 lines
520 B
Ruby
26 lines
520 B
Ruby
class EncryptionService
|
|
KEY = ActiveSupport::KeyGenerator.new(
|
|
ENV.fetch('SECRET_KEY_BASE')
|
|
).generate_key(
|
|
ENV.fetch('ENCRYPTION_SERVICE_SALT'),
|
|
ActiveSupport::MessageEncryptor.key_len
|
|
).freeze
|
|
|
|
private_constant :KEY
|
|
|
|
delegate :encrypt_and_sign, :decrypt_and_verify, to: :encryptor
|
|
|
|
def self.encrypt(value)
|
|
new.encrypt_and_sign(value)
|
|
end
|
|
|
|
def self.decrypt(value)
|
|
new.decrypt_and_verify(value)
|
|
end
|
|
|
|
private
|
|
|
|
def encryptor
|
|
ActiveSupport::MessageEncryptor.new(KEY)
|
|
end
|
|
end
|