Class: Rtprov::Encryption
- Inherits:
-
Object
- Object
- Rtprov::Encryption
- Defined in:
- lib/rtprov/encryption.rb
Constant Summary collapse
- KEY_FILE =
"encryption_key".freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
- .decrypt(encrypted, key = load_key) ⇒ Object
- .encrypt(plain, key = load_key) ⇒ Object
- .generate_key ⇒ Object
- .load_key ⇒ Object
Instance Method Summary collapse
- #decrypt(encrypted) ⇒ Object
- #encrypt(plain) ⇒ Object
-
#initialize(key) ⇒ Encryption
constructor
A new instance of Encryption.
Constructor Details
#initialize(key) ⇒ Encryption
Returns a new instance of Encryption.
26 27 28 |
# File 'lib/rtprov/encryption.rb', line 26 def initialize(key) @key = key.dup.freeze end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/rtprov/encryption.rb', line 8 def key @key end |
Class Method Details
.decrypt(encrypted, key = load_key) ⇒ Object
18 19 20 |
# File 'lib/rtprov/encryption.rb', line 18 def self.decrypt(encrypted, key = load_key) new(key).decrypt(encrypted) end |
.encrypt(plain, key = load_key) ⇒ Object
14 15 16 |
# File 'lib/rtprov/encryption.rb', line 14 def self.encrypt(plain, key = load_key) new(key).encrypt(plain) end |
.generate_key ⇒ Object
22 23 24 |
# File 'lib/rtprov/encryption.rb', line 22 def self.generate_key SecureRandom.base64(512) end |
Instance Method Details
#decrypt(encrypted) ⇒ Object
34 35 36 |
# File 'lib/rtprov/encryption.rb', line 34 def decrypt(encrypted) ReversibleCryptography::Message.decrypt(encrypted, key) end |
#encrypt(plain) ⇒ Object
30 31 32 |
# File 'lib/rtprov/encryption.rb', line 30 def encrypt(plain) ReversibleCryptography::Message.encrypt(plain, key) end |