Method: PathgraphEncoding::PrivateKey.to_der
- Defined in:
- lib/pathgraph_encoding.rb
.to_der(key) ⇒ Object
Compute DER-formatted bytes array of a pathgraph private key.
Parameters:
- key
-
A private key to encode.
Returns:
A byte array representing the private key specified.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pathgraph_encoding.rb', line 49 def self.to_der(key) n = OpenSSL::ASN1::Integer.new(key[:n]) pi = OpenSSL::ASN1::Sequence.new( key[:pi].map do |p| arr = p.map { |x| OpenSSL::ASN1::Integer.new(x) } OpenSSL::ASN1::Sequence.new(arr) end ) privateKey = OpenSSL::ASN1::Sequence.new([n,pi]) version = OpenSSL::ASN1::PrintableString.new("0.0.1") instance = OpenSSL::ASN1::Sequence.new([version,privateKey]) instance.to_der end |