Last active
December 31, 2015 08:39
-
-
Save Aerotune/7961606 to your computer and use it in GitHub Desktop.
Verify identity of sender of a message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
key = OpenSSL::PKey::EC.new("secp112r1").generate_key | |
#puts "Private Key:" | |
#p key.to_pem | |
## Recreate key from pem | |
#key = OpenSSL::PKey::EC.new(key.to_pem) | |
public_key = OpenSSL::PKey::EC.new("secp112r1") | |
public_key.public_key = key.public_key | |
#puts "Public Key:" | |
#p public_key.to_pem | |
## Recreate key from pem | |
#public_key = OpenSSL::PKey::EC.new(public_key.to_pem) | |
def verify key, message, signature | |
key.dsa_verify_asn1(message, signature) | |
end | |
message = 'Chunky Bacon' | |
signature = key.dsa_sign_asn1 message | |
## How to get the size of the signature | |
#signature_size = signature[1].ord + 2 | |
#puts signature_size == signature.bytesize | |
## to make it fail | |
## try changing the signature | |
#signature[8] = 'a' | |
## or the message | |
#message['Chunky'] = 'Crunchy' | |
puts verify(public_key, message, signature) ? "Verified" : "Not verified!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment