Module: Duse::Encryption
- Defined in:
- lib/duse/encryption.rb
Class Method Summary collapse
- .decode(encoded_text) ⇒ Object
- .decrypt(private_key, text) ⇒ Object
- .digest ⇒ Object
- .encode(plain_text) ⇒ Object
- .encrypt(private_key, public_key, text) ⇒ Object
- .sign(private_key, text) ⇒ Object
- .verify(public_key, signature, encrypted) ⇒ Object
Class Method Details
.decode(encoded_text) ⇒ Object
34 35 36 |
# File 'lib/duse/encryption.rb', line 34 def decode(encoded_text) Base64.decode64(encoded_text.encode('ascii-8bit')).force_encoding('utf-8') end |
.decrypt(private_key, text) ⇒ Object
18 19 20 |
# File 'lib/duse/encryption.rb', line 18 def decrypt(private_key, text) private_key.private_decrypt(decode(text)).force_encoding('utf-8') end |
.digest ⇒ Object
26 27 28 |
# File 'lib/duse/encryption.rb', line 26 def digest OpenSSL::Digest::SHA256.new end |
.encode(plain_text) ⇒ Object
30 31 32 |
# File 'lib/duse/encryption.rb', line 30 def encode(plain_text) Base64.encode64(plain_text).encode('utf-8') end |
.encrypt(private_key, public_key, text) ⇒ Object
8 9 10 11 12 |
# File 'lib/duse/encryption.rb', line 8 def encrypt(private_key, public_key, text) encrypted = public_key.public_encrypt text.force_encoding('ascii-8bit') signature = sign(private_key, encrypted) [encode(encrypted), signature] end |
.sign(private_key, text) ⇒ Object
14 15 16 |
# File 'lib/duse/encryption.rb', line 14 def sign(private_key, text) encode(private_key.sign(digest, text)) end |
.verify(public_key, signature, encrypted) ⇒ Object
22 23 24 |
# File 'lib/duse/encryption.rb', line 22 def verify(public_key, signature, encrypted) public_key.verify digest, decode(signature), decode(encrypted) end |