An X.509 name represents a hostname, email address or other entity associated with a public key.

You can create a Name by parsing a distinguished name String or by supplying the distinguished name as an Array.

name = OpenSSL::X509::Name.parse '/CN=nobody/DC=example'

name = [['CN', 'nobody'], ['DC', 'example']]

A flag for to_s.

Breaks the name returned into multiple lines if longer than 80 characters.

The default object type for name entries.

A flag for to_s.

Returns a multiline format.

The default object type template for name entries.

A flag for to_s.

Returns a more readable format than RFC2253.

A flag for to_s.

Returns an RFC2253 format name.

Class Methods

Creates a new Name.

A name may be created from a DER encoded string der, an Array representing a distinguished_name or a distinguished_name along with a template.

name = [['CN', 'nobody'], ['DC', 'example']]

name = name.to_der

See add_entry for a description of the distinguished_name Array’s contents

An alias for parse_openssl
No documentation available
No documentation available
Instance Methods
An alias for cmp

Adds a new entry with the given oid and value to this name. The oid is an object identifier defined in ASN.1. Some common OIDs are:


Country Name


Common Name


Domain Component


Organization Name


Organizational Unit Name


State or Province Name

The optional keyword parameters loc and set specify where to insert the new attribute. Refer to the manpage of X509_NAME_add_entry(3) for details. loc defaults to -1 and set defaults to 0. This appends a single-valued RDN to the end.

Compares this Name with other and returns 0 if they are the same and -1 or +1 if they are greater or less than each other respectively. Returns nil if they are not comparable (i.e. different types).

Returns true if name and other refer to the same hash key.

The hash value returned is suitable for use as a certificate’s filename in a CA path.

Returns an MD5 based hash used in OpenSSL 0.9.X.

No documentation available
No documentation available

Returns an Array representation of the distinguished name suitable for passing to ::new

Converts the name to DER encoding

Returns a String representation of the Distinguished Name. format is one of:

If format is omitted, the largely broken and traditional OpenSSL format is used.

Returns an UTF-8 representation of the distinguished name, as specified in RFC 2253.