Class: EYAML::EncryptionManager
- Inherits:
-
Object
- Object
- EYAML::EncryptionManager
- Defined in:
- lib/eyaml/encryption_manager.rb
Constant Summary collapse
- FORMAT_REGEX =
/\AEJ\[(?<version>[^:]+):(?<session_public_key>[^:]+):(?<nonce>[^:]+):(?<text>[^\]]+)\]\z/
- FORMAT_VERSION =
"1"
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt ⇒ Object
- #encrypt ⇒ Object
-
#initialize(yaml, public_key, private_key = nil) ⇒ EncryptionManager
constructor
A new instance of EncryptionManager.
Constructor Details
#initialize(yaml, public_key, private_key = nil) ⇒ EncryptionManager
Returns a new instance of EncryptionManager.
19 20 21 22 23 |
# File 'lib/eyaml/encryption_manager.rb', line 19 def initialize(yaml, public_key, private_key = nil) @tree = yaml @public_key = RbNaCl::Util.hex2bin(public_key) @private_key = private_key && RbNaCl::Util.hex2bin(private_key.strip) end |
Class Method Details
.new_keypair ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/eyaml/encryption_manager.rb', line 9 def new_keypair private_key = RbNaCl::PrivateKey.generate [ RbNaCl::Util.bin2hex(private_key.public_key), RbNaCl::Util.bin2hex(private_key) ] end |
Instance Method Details
#decrypt ⇒ Object
25 26 27 28 29 |
# File 'lib/eyaml/encryption_manager.rb', line 25 def decrypt traverse(@tree) do |text| encrypted?(text) ? decrypt_text(text) : text end end |
#encrypt ⇒ Object
31 32 33 34 35 |
# File 'lib/eyaml/encryption_manager.rb', line 31 def encrypt traverse(@tree) do |text| encrypted?(text) ? text : encrypt_text(text) end end |