Class: SimpleScripting::Configuration::Value
- Inherits:
-
String
- Object
- String
- SimpleScripting::Configuration::Value
- Defined in:
- lib/simple_scripting/configuration/value.rb
Overview
The purpose of encryption in this library is just to avoid displaying passwords in plaintext; it’s not considered safe against attacks.
Constant Summary collapse
- ENCRYPTION_CIPHER =
'des3'
Instance Method Summary collapse
- #decrypted ⇒ Object
- #encrypted ⇒ Object
- #full_path ⇒ Object
- #full_paths ⇒ Object
-
#initialize(string, encryption_key = nil) ⇒ Value
constructor
A new instance of Value.
Constructor Details
#initialize(string, encryption_key = nil) ⇒ Value
Returns a new instance of Value.
15 16 17 18 19 20 21 |
# File 'lib/simple_scripting/configuration/value.rb', line 15 def initialize(string, encryption_key = nil) super(string) if encryption_key @encryption_key = encryption_key + '*' * (24 - encryption_key.bytesize) end end |
Instance Method Details
#decrypted ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/simple_scripting/configuration/value.rb', line 31 def decrypted raise "Encryption key not provided!" if @encryption_key.nil? ciphertext = Base64.decode64(self) cipher = OpenSSL::Cipher::Cipher.new(ENCRYPTION_CIPHER) cipher.decrypt cipher.key = @encryption_key cipher.iv = ciphertext[0...cipher.iv_len] plaintext = cipher.update(ciphertext[cipher.iv_len..-1]) + cipher.final plaintext end |
#encrypted ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/simple_scripting/configuration/value.rb', line 47 def encrypted cipher = OpenSSL::Cipher::Cipher.new(ENCRYPTION_CIPHER) cipher.encrypt iv = cipher.random_iv cipher.key = @encryption_key cipher.iv = iv ciphertext = iv + cipher.update(self) + cipher.final Base64.encode64(ciphertext).rstrip end |
#full_path ⇒ Object
23 24 25 |
# File 'lib/simple_scripting/configuration/value.rb', line 23 def full_path start_with?('/') ? self : File.(self, '~') end |
#full_paths ⇒ Object
27 28 29 |
# File 'lib/simple_scripting/configuration/value.rb', line 27 def full_paths split(':').map { |value| self.class.new(value).full_path } end |