Created
June 29, 2011 21:42
-
-
Save bkerley/1055073 to your computer and use it in GitHub Desktop.
ruby ECDSA fun time
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
# derived from http://h2np.net/tips/wiki/index.php?RubyOpenSSLDigitalSignatureSample | |
require 'openssl' | |
require 'base64' | |
include OpenSSL | |
group_name = 'secp521r1' | |
message = '10000 fartbux sent to bryce from a can of beans' | |
key = PKey::EC.new(group_name) | |
key = key.generate_key | |
puts 'private' | |
puts key.to_text | |
puts 'public' | |
puts key.public_key.to_bn | |
digest = Digest::SHA512.digest(message) | |
puts 'digest' | |
puts Base64.encode64 digest | |
signature = key.dsa_sign_asn1 digest | |
puts 'signature' | |
puts Base64.encode64 signature | |
group = PKey::EC::Group.new(group_name) | |
point = PKey::EC::Point.new(group, key.public_key.to_bn) | |
# verifier = PKey::EC.new(group) | |
verifier = key | |
verifier.private_key = nil | |
verifier.public_key = point | |
puts 'verify key' | |
puts verifier.to_text | |
puts 'verifying:' | |
puts verifier.dsa_verify_asn1(digest, signature).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment