Module: Secrets

Extended by:
RequireDir
Included in:
App::CLI, App::Commands::DeleteKeychainKey, App::Commands::EncryptDecrypt, App::Commands::GenerateKey, App::Commands::OpenEditor
Defined in:
lib/secrets.rb,
lib/secrets.rb,
lib/secrets/app.rb,
lib/secrets/data.rb,
lib/secrets/errors.rb,
lib/secrets/app/cli.rb,
lib/secrets/version.rb,
lib/secrets/app/commands.rb,
lib/secrets/app/keychain.rb,
lib/secrets/data/decoder.rb,
lib/secrets/data/encoder.rb,
lib/secrets/configuration.rb,
lib/secrets/cipher_handler.rb,
lib/secrets/app/outputs/to_file.rb,
lib/secrets/data/wrapper_struct.rb,
lib/secrets/app/commands/command.rb,
lib/secrets/app/password_handler.rb,
lib/secrets/app/outputs/to_stdout.rb,
lib/secrets/app/commands/show_help.rb,
lib/secrets/app/commands/open_editor.rb,
lib/secrets/extensions/class_methods.rb,
lib/secrets/app/commands/generate_key.rb,
lib/secrets/app/commands/show_version.rb,
lib/secrets/app/commands/show_examples.rb,
lib/secrets/extensions/instance_methods.rb,
lib/secrets/app/commands/encrypt_decrypt.rb,
lib/secrets/app/commands/delete_keychain_key.rb

Overview

Include Secrets in your class to enable functionality of this library.

Once included, you would normally use #encr and #decr instance methods to perform encryption and decryption of object of any type using a symmetric key encryption.

You could also use #encr_password and #decr_password if you prefer to encrypt with a password instead. The encryption key is generated from the password in that case.

Create a new key with #create_private_key class method, which returns a new key every time it’s called, or with #private_key class method, which either assigns, or creates and caches the private key at a class level.

“‘ruby require ’secrets’ class TestClass

include Secrets
private_key ENV['PRIVATE_KEY']

def sensitive_value=(value)
  @sensitive_value = encr(value, self.class.private_key)
end

def sensitive_value
  decr(@sensitive_value, self.class.private_key)
end

end “‘

Defined Under Namespace

Modules: App, CipherHandler, Data, Errors, Extensions Classes: Configuration

Constant Summary collapse

VERSION =
'1.2.1'

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/secrets.rb', line 52

def self.included(klass)
  klass.instance_eval do
    include ::Secrets::Extensions::InstanceMethods
    extend ::Secrets::Extensions::ClassMethods
    class << self
      def private_key(value = nil)
        if value
          @private_key= value
        elsif @private_key
          @private_key
        else
          @private_key= self.create_private_key
        end
        @private_key
      end
    end
  end
end