Sha256: c840d6a3c705e79a53ca22ea66ef05d6f2a20ce6e2ec48c4c5a868fc5fbd5feb
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module Cryptosphere module Handshake module_function def encode_request(sender, recipient) # TODO: encrypt sender's public key # Sure would be nice to have some Curve25519 here message = sender.public_key Cryptosphere.sign(sender.private_key, message) + message end def decode_request(recipient, message) bytes = PUBKEY_SIZE / 8 signature, message = message[0...bytes], message[bytes..-1] # FIXME: this should be encrypted :( sender_key = message Cryptosphere.verify!(sender_key, message, signature) sender_key end def encode_response(sender, recipient, secret = Cryptosphere.random_bytes(32)) cipher = AsymmetricCipher.new(recipient.public_key) message = cipher.public_encrypt(secret) Cryptosphere.sign(sender.private_key, message) + message end def decode_response(recipient, sender, message) bytes = PUBKEY_SIZE / 8 signature, message = message[0...bytes], message[bytes..-1] Cryptosphere.verify!(sender.public_key, message, signature) cipher = AsymmetricCipher.new(recipient.private_key) cipher.private_decrypt(message) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cryptosphere-0.0.0 | lib/cryptosphere/protocol/handshake.rb |