Class: Signer
- Inherits:
-
Object
- Object
- Signer
- Defined in:
- lib/signer.rb
Defined Under Namespace
Modules: Key
Instance Method Summary collapse
-
#initialize(wmid, password, key) ⇒ Signer
constructor
A new instance of Signer.
- #sign(data) ⇒ Object
Constructor Details
#initialize(wmid, password, key) ⇒ Signer
Returns a new instance of Signer.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/signer.rb', line 82 def initialize(wmid, password, key) raise ArgumentError, "nil wmid" if wmid.nil? raise ArgumentError, "Incorrect WMID" unless is_wmid wmid raise ArgumentError, "nil password" if password.nil? raise ArgumentError, "nil key" if key.nil? key = Base64.decode64 key raise ArgumentError, "Illegal size for keydata" if key.length != 164 io = StringIO.open key.force_encoding('BINARY'), 'rb' @key = Key.read io, wmid, password end |
Instance Method Details
#sign(data) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/signer.rb', line 95 def sign(data) raise ArgumentError, "nil data" if data.nil? digest = OpenSSL::Digest::MD4.new digest.update data data = digest.digest.unpack("V*") 10.times do data << SecureRandom.random_number(1 << 32) end data = data.pack("V*") data = ([ data.length ].pack("v") + data).ljust( @key[:n].num_bytes, 0.chr).reverse data_bignum = OpenSSL::BN.new data, 2 signature = data_bignum.mod_exp(@key[:e], @key[:n]) signature.to_s(2).rjust(@key[:n].num_bytes, 0.chr).unpack('n*').reverse.map { |w| sprintf '%04x', w }.join end |