LoginSignup
0
0

More than 5 years have passed since last update.

Ruby で Ethereum の秘密鍵・アドレスを生成

Last updated at Posted at 2018-05-09
require 'openssl'
require 'base16'
require 'digest/sha3'

def eth_address(public_key)
    s = public_key[2, 128]
    s.downcase!
    s = Base16.decode16(s)
    h = Digest::SHA3.hexdigest(s, 256)
    a = '0x' + h[-40..-1]
    return a
end

ec = OpenSSL::PKey::EC.new('secp256k1')
ec.generate_key

public_key = ec.public_key.to_bn.to_s(16)
private_key = ec.private_key.to_s(16)
eth_address = eth_address(public_key)

puts "address: #{eth_address}"
puts "private_key: #{private_key}"

Note

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0