Skip to content
class method

OpenSSL::PKey::DSA.new

(::String pem, ?::String pass) -> ::OpenSSL::PKey::DSA
(?::Integer size) -> ::OpenSSL::PKey::DSA
DSA.new → dsa
DSA.new(string [, pass]) → dsa
DSA.new(size) → dsa

Creates a new DSA instance by reading an existing key from string.

If called without arguments, creates a new instance with no key components set. They can be set individually by set_pqg and set_key. This form is not compatible with OpenSSL 3.0 or later.

If called with a String, tries to parse as DER or PEM encoding of a DSA key. See also OpenSSL::PKey.read which can parse keys of any kinds.

If called with a number, generates random parameters and a key pair. This form works as an alias of DSA.generate.

string

A String that contains a DER or PEM encoded key.

pass

A String that contains an optional password.

size

See DSA.generate.

Examples:

Example
p OpenSSL::PKey::DSA.new(1024)
#=> #<OpenSSL::PKey::DSA:0x000055a8d6025bf0 oid=DSA>

p OpenSSL::PKey::DSA.new(File.read('dsa.pem'))
#=> #<OpenSSL::PKey::DSA:0x000055555d6b8110 oid=DSA>

p OpenSSL::PKey::DSA.new(File.read('dsa.pem'), 'mypassword')
#=> #<OpenSSL::PKey::DSA:0x0000556f973c40b8 oid=DSA>
See also .generate #export #params also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0