Module: Shhh
- Extended by:
- RequireDir
- Included in:
- App::Commands::EncryptDecrypt, App::Commands::GenerateKey, App::Commands::OpenEditor, App::PrivateKey::Decryptor, App::PrivateKey::Handler, EncryptedFile
- Defined in:
- lib/shhh.rb,
lib/shhh.rb,
lib/shhh/app.rb,
lib/shhh/data.rb,
lib/shhh/errors.rb,
lib/shhh/app/cli.rb,
lib/shhh/app/nlp.rb,
lib/shhh/version.rb,
lib/shhh/app/args.rb,
lib/shhh/app/cache.rb,
lib/shhh/app/output.rb,
lib/shhh/application.rb,
lib/shhh/app/commands.rb,
lib/shhh/app/keychain.rb,
lib/shhh/data/decoder.rb,
lib/shhh/data/encoder.rb,
lib/shhh/app/nlp/usage.rb,
lib/shhh/configuration.rb,
lib/shhh/app/short_name.rb,
lib/shhh/cipher_handler.rb,
lib/shhh/encrypted_file.rb,
lib/shhh/app/output/base.rb,
lib/shhh/app/output/file.rb,
lib/shhh/app/output/noop.rb,
lib/shhh/app/input/handler.rb,
lib/shhh/app/nlp/constants.rb,
lib/shhh/app/output/stdout.rb,
lib/shhh/app/nlp/translator.rb,
lib/shhh/data/wrapper_struct.rb,
lib/shhh/app/commands/command.rb,
lib/shhh/app/commands/print_key.rb,
lib/shhh/app/commands/show_help.rb,
lib/shhh/app/private_key/handler.rb,
lib/shhh/app/commands/open_editor.rb,
lib/shhh/app/private_key/detector.rb,
lib/shhh/extensions/class_methods.rb,
lib/shhh/app/commands/generate_key.rb,
lib/shhh/app/commands/show_version.rb,
lib/shhh/app/private_key/decryptor.rb,
lib/shhh/app/commands/show_examples.rb,
lib/shhh/extensions/instance_methods.rb,
lib/shhh/app/commands/encrypt_decrypt.rb,
lib/shhh/app/private_key/base64_decoder.rb,
lib/shhh/app/commands/delete_keychain_item.rb,
lib/shhh/app/commands/show_language_examples.rb
Overview
Using Shhh Library
This library is a “wrapper” that allows you to take advantage of the symmetric encryption functionality provided by the OpenSSL gem (and the underlying C library). In order to use the library in your ruby classes, you should include the module Shhh.
The including class is decorated with four instance methods from the module Extensions::InstanceMethods and two class methods from Extensions::ClassMethods – for specifics, please refer there.
The two main instance methods are #encr
and #decr
, which as the name implies, perform two-way symmetric encryption and decryption of any Ruby object that can be marshaled
.
Two additional instance methods #encr_password
and #decr_password
turn on password-based encryption, which actually uses a password to construct a 128-bit long private key, and then uses that in the encryption of the data. You could use them to encrypt data with a password instead of a randomly generated private key.
The library comes with a rich CLI interface, which is mostly encapsulated under the Shhh::App
namespace.
The shhh
executable that is the “app” in this case, and is a user of the API methods #encr
and #decr
.
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.
Example
require 'shhh'
class TestClass
include Shhh
# read the key from environmant variable and assign to this class.
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
Private Key
They private key can be generated by TestClass.create_private_key
which returns but does not store a new random 256-bit key.
The key can be assigned and saved, or auto-generated and saved using the #private_key
method on the class that includes the Shhh
module.
Each class including the Shhh
module would get their own +#private_key# class-instance variable accessor, and a possible value.
For example:
Defined Under Namespace
Modules: App, CipherHandler, Data, Errors, Extensions Classes: Application, Configuration, EncryptedFile
Constant Summary collapse
- VERSION =
'1.6.4'