Project

General

Profile

Feature #9830 ยป gost_sigining.rb

Test script: digital signature creating and verifying - Envek (Andrey Novikov), 05/11/2014 08:27 PM

 
1
require 'openssl'
2
OpenSSL::Engine.load
3
gost_engine = OpenSSL::Engine.by_id('gost')
4
gost_engine.set_default(0xFFFF)
5

    
6
crt = OpenSSL::X509::Certificate.new(File.read('gost_r_34_10_2001_certificate.pem'))
7
privkey = OpenSSL::PKey.read(File.read('gost_r_34_10_2001_private_key.pem'))
8

    
9
data = 'Some message'
10

    
11
dgst94  = gost_engine.digest('md_gost94')
12
signature = privkey.sign(dgst94, data)
13

    
14
puts crt.public_key.verify(dgst94, signature, data) # Should be true
15
puts crt.public_key.verify(dgst94, signature, data.sub('S', 'Not s')) # Should be false