Module: Duse::Encryption::Asymmetric
Instance Method Summary collapse
- #decrypt(private_key, text) ⇒ Object
- #digest ⇒ Object
- #encrypt(private_key, public_key, text) ⇒ Object
- #sign(private_key, text) ⇒ Object
- #verify(public_key, signature, encrypted) ⇒ Object
Methods included from Encoding
Instance Method Details
#decrypt(private_key, text) ⇒ Object
31 32 33 |
# File 'lib/duse/encryption.rb', line 31 def decrypt(private_key, text) private_key.private_decrypt(decode(text)).force_encoding('utf-8') end |
#digest ⇒ Object
39 40 41 |
# File 'lib/duse/encryption.rb', line 39 def digest OpenSSL::Digest::SHA256.new end |
#encrypt(private_key, public_key, text) ⇒ Object
21 22 23 24 25 |
# File 'lib/duse/encryption.rb', line 21 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
27 28 29 |
# File 'lib/duse/encryption.rb', line 27 def sign(private_key, text) encode(private_key.sign(digest, text)) end |
#verify(public_key, signature, encrypted) ⇒ Object
35 36 37 |
# File 'lib/duse/encryption.rb', line 35 def verify(public_key, signature, encrypted) public_key.verify digest, decode(signature), decode(encrypted) end |