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.
67 68 69 |
# File 'lib/inline_encryption/base.rb', line 67 def config @config ||= Config.new end |
#decrypt(data, fail_text = nil) ⇒ String
Returns decrypted target.
55 56 57 58 59 60 61 62 63 |
# File 'lib/inline_encryption/base.rb', line 55 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.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/inline_encryption/base.rb', line 38 def decrypt!(data) config.check_required_variables begin converted = Base64.decode64(data) this_key = config.real_key.private? ? config.real_key.public_key : config.real_key decrypted = this_key.public_decrypt(converted) rescue => e err = DecryptionFailureError.exception "Encrypted: #{data}" raise err end end |
#encrypt(data, fail_text = nil) ⇒ String
Returns encrypted target, or fail_text on error (default data).
24 25 26 27 28 29 30 31 32 |
# File 'lib/inline_encryption/base.rb', line 24 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.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/inline_encryption/base.rb', line 9 def encrypt!(data) config.check_required_variables begin encrypted = config.real_key.private_encrypt(data) converted = Base64.encode64(encrypted) rescue => e err = EncryptionFailureError.exception "Target: #{data}" raise err end end |