Module: Asymmetric
- Defined in:
- lib/aspis/asymmetric.rb
Class Method Summary collapse
- .decrypt(input, public_key, private_key, ask_pass) ⇒ Object
- .encrypt(plaintext, public_key, private_key, ask_pass) ⇒ Object
Class Method Details
.decrypt(input, public_key, private_key, ask_pass) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/aspis/asymmetric.rb', line 28 def self.decrypt(input, public_key, private_key, ask_pass) sender_public_key = File.read(public_key) sender_public_key = Base64.decode64(sender_public_key) recipient_private_key = File.read(private_key) recipient_private_key = Symmetric.decrypt(recipient_private_key, ask_pass) box = RbNaCl::SimpleBox.from_keypair(sender_public_key, recipient_private_key) input = JSON.parse(input) ciphertext = input['ciphertext'] ciphertext = Base64.decode64(ciphertext) box.decrypt(ciphertext) end |
.encrypt(plaintext, public_key, private_key, ask_pass) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/aspis/asymmetric.rb', line 12 def self.encrypt(plaintext, public_key, private_key, ask_pass) recipient_public_key = File.read(public_key) recipient_public_key = Base64.decode64(recipient_public_key) sender_private_key = File.read(private_key) sender_private_key = Symmetric.decrypt(sender_private_key, ask_pass) box = RbNaCl::SimpleBox.from_keypair(recipient_public_key, sender_private_key) ciphertext = box.encrypt(plaintext) ciphertext = Base64.strict_encode64(ciphertext) output = { version: Aspis::VERSION, ciphertext: ciphertext } JSON.generate(output) end |