class OpenSSL::PKey::EC
See ruby-doc.org/stdlib/libdoc/openssl/rdoc/OpenSSL/PKey/EC.html
Public Instance Methods
to_der_pkcs8()
click to toggle source
Returns EC
(private) key in PKCS#8 DER format.
# File lib/openssl_pkcs8_pure.rb, line 59 def to_der_pkcs8 #[todo] OpenSSL::PKey::EC#public_key does not respond to to_pem #return to_der if !private? asn1=OpenSSL::ASN1.decode(to_der).value #curve_name=asn1[2].value[0].value curve_name=group.curve_name asn1.delete_at(2) asn1=OpenSSL::ASN1::Sequence(asn1) OpenSSL::ASN1::Sequence([ OpenSSL::ASN1::Integer(0), OpenSSL::ASN1::Sequence([OpenSSL::ASN1::ObjectId("id-ecPublicKey"),OpenSSL::ASN1::ObjectId(curve_name)]), OpenSSL::ASN1::OctetString(asn1.to_der) ]).to_der end
to_pem_pkcs8()
click to toggle source
Returns EC
(private) key in PKCS#8 PEM format.
# File lib/openssl_pkcs8_pure.rb, line 74 def to_pem_pkcs8 #return to_pem if !private? body=RUBY_VERSION<'1.9' ? Base64.encode64(to_der_pkcs8) : Base64.strict_encode64(to_der_pkcs8).chars.each_slice(64).map(&:join).join("\n")+"\n" "-----BEGIN PRIVATE KEY-----\n"+body+"-----END PRIVATE KEY-----\n" end