Skip to content

Instantly share code, notes, and snippets.

@rrrene
Forked from bkerley/ecc.rb
Created May 15, 2013 10:50
Show Gist options
  • Save rrrene/5583135 to your computer and use it in GitHub Desktop.
Save rrrene/5583135 to your computer and use it in GitHub Desktop.
# 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