class OpenSesame::Message
Used for passing messages that cannot be altered. This is not for hiding a message from observers. The message is cryptographically signed but it is not encrypted.
Public Class Methods
Generate a message string that can be verified by another computer that knows the shared secret.
@param [String] message The message. @param [String] secret The shared secret phrase.
# File lib/open-sesame.rb, line 47 def self.generate(message, secret = @@default_secret) hash = (Digest::SHA1.new << secret + message).to_s message + '-' + hash end
Verify a message that was generated with OpenSesame
and return just the message part. Returns nil if the message does not verify.
@param [String] message The message that was generated by OpenSesame
, which includes
a cryptographic hash.
@param [String] secret The secret to use for verifying the message.
# File lib/open-sesame.rb, line 67 def self.message(message, secret = @@default_secret) if self.verify(message, secret) (message.split /-/).first else nil end end
Verify that the message has not been altered.
@param [String] message The message to verify. @param [String] secret The shared secret phrase.
# File lib/open-sesame.rb, line 56 def self.verify(message, secret = @@default_secret) string = message.split /-/ message.eql? generate(string.first, secret) end