Module: InlineEncryption::Base
- Included in:
- InlineEncryption
- Defined in:
- lib/inline_encryption/base.rb
Instance Method Summary collapse
-
#config ⇒ InlineEncryption::Config
The configuration instance.
-
#decrypt(data, fail_text = nil) ⇒ String
Decrypted target.
-
#decrypt!(data) ⇒ String
Decrypted target.
-
#encrypt(data, fail_text = nil) ⇒ String
Encrypted target, or fail_text on error (default data).
-
#encrypt!(data) ⇒ String
Encrypted target.
Instance Method Details
#config ⇒ InlineEncryption::Config
Returns the configuration instance.
69 70 71 |
# File 'lib/inline_encryption/base.rb', line 69 def config @config ||= Config.new end |
#decrypt(data, fail_text = nil) ⇒ String
Returns decrypted target.
57 58 59 60 61 62 63 64 65 |
# File 'lib/inline_encryption/base.rb', line 57 def decrypt(data, fail_text=nil) config.check_required_variables begin decrypt!(data) rescue DecryptionFailureError => e return fail_text.nil? ? data : fail_text.to_s end end |
#decrypt!(data) ⇒ String
Returns decrypted target.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inline_encryption/base.rb', line 40 def decrypt!(data) config.check_required_variables raise MisconfigurationError.new(I18n.t('error.pub_key_decrypt')) unless config.real_key.private? begin converted = Base64.decode64(data) decrypted = config.real_key.private_decrypt(converted) rescue => e err = DecryptionFailureError.exception I18n.t('encrypted', data) raise err end end |
#encrypt(data, fail_text = nil) ⇒ String
Returns encrypted target, or fail_text on error (default data).
26 27 28 29 30 31 32 33 34 |
# File 'lib/inline_encryption/base.rb', line 26 def encrypt(data, fail_text=nil) config.check_required_variables begin encrypt!(data) rescue EncryptionFailureError => e return fail_text.nil? ? data : fail_text.to_s end end |
#encrypt!(data) ⇒ String
Returns encrypted target.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/inline_encryption/base.rb', line 11 def encrypt!(data) config.check_required_variables begin encrypted = config.real_key.public_encrypt(data) converted = Base64.encode64(encrypted) rescue => e err = EncryptionFailureError.exception I18n.t('target', data: data) raise err end end |