123456789_123456789_123456789_123456789_123456789_

Class: OpenSSL::PKey::DSA

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PKey
Instance Chain:
self, PKey
Inherits: OpenSSL::PKey::PKey
Defined in: ext/openssl/ossl_pkey_dsa.c

Overview

DSA, the Digital Signature Algorithm, is specified in NIST's FIPS 186-3. It is an asymmetric public key algorithm that may be used similar to e.g. RSA. Please note that for ::OpenSSL versions prior to 1.0.0 the digest algorithms OpenSSL::Digest::DSS (equivalent to SHA) or OpenSSL::Digest::DSS1 (equivalent to SHA-1) must be used for issuing signatures with a DSA key using OpenSSL::PKey#sign. Starting with ::OpenSSL 1.0.0, digest algorithms are no longer restricted, any ::OpenSSL::Digest may be used for signing.

Class Method Summary

  • .generate(size) ⇒ DSA

    Creates a new DSA instance by generating a private/public key pair from scratch.

  • .new ⇒ DSA constructor

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

PKey - Inherited

.new

Because PKey is an abstract class, actually calling this method explicitly will raise a NotImplementedError.

Instance Attribute Summary

  • #private? ⇒ Boolean readonly

    Indicates whether this DSA instance has a private key associated with it or not.

  • #public? ⇒ Boolean readonly

    Indicates whether this DSA instance has a public key associated with it or not.

Instance Method Summary

PKey - Inherited

#sign

To sign the String data, digest, an instance of ::OpenSSL::Digest, must be provided.

#verify

To verify the String signature, digest, an instance of ::OpenSSL::Digest, must be provided to re-compute the message digest of the original data, also a String.

Constructor Details

.newDSA .new(size) ⇒ DSA .new(string [, pass]) ⇒ DSA

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

Parameters

  • size is an integer representing the desired key size.

  • string contains a DER or PEM encoded key.

  • pass is a string that contains an optional password.

Examples

DSA.new -> dsa
DSA.new(1024) -> dsa
DSA.new(File.read('dsa.pem')) -> dsa
DSA.new(File.read('dsa.pem'), 'mypassword') -> dsa

Class Method Details

.generate(size) ⇒ DSA

Creates a new DSA instance by generating a private/public key pair from scratch.

Parameters

  • size is an integer representing the desired key size.

Instance Attribute Details

#private?Boolean (readonly)

Indicates whether this DSA instance has a private key associated with it or not. The private key may be retrieved with DSA#private_key.

#public?Boolean (readonly)

Indicates whether this DSA instance has a public key associated with it or not. The public key may be retrieved with #public_key.

Instance Method Details

#export([cipher, password]) ⇒ String #to_pem([cipher, password]) ⇒ String #to_s([cipher, password]) ⇒ String

Alias for #to_s.

#paramsHash

Stores all parameters of key to the hash INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!! Don't use :-)) (I's up to you)

#public_keyDSA

Returns a new DSA instance that carries just the public key information. If the current instance has also private key information, this will no longer be present in the new instance. This feature is helpful for publishing the public key information without leaking any of the private information.

Example

dsa = OpenSSL::PKey::DSA.new(2048) # has public and private information
pub_key = dsa.public_key # has only the public part available
pub_key_der = pub_key.to_der # it's safe to publish this

#set_key(pub_key, priv_key) ⇒ self

Sets pub_key and priv_key for the DSA instance. priv_key may be nil.

#set_pqg(p, q, g) ⇒ self

Sets p, q, g for the DSA instance.

#syssign(string) ⇒ String

Computes and returns the DSA signature of string, where string is expected to be an already-computed message digest of the original input data. The signature is issued using the private key of this DSA instance.

Parameters

  • string is a message digest of the original input data to be signed

Example

dsa = OpenSSL::PKey::DSA.new(2048)
doc = "Sign me"
digest = OpenSSL::Digest::SHA1.digest(doc)
sig = dsa.syssign(digest)

#sysverify(digest, sig) ⇒ Boolean

Verifies whether the signature is valid given the message digest input. It does so by validating sig using the public key of this DSA instance.

Parameters

  • digest is a message digest of the original input data to be signed

  • sig is a DSA signature value

Example

dsa = OpenSSL::PKey::DSA.new(2048)
doc = "Sign me"
digest = OpenSSL::Digest::SHA1.digest(doc)
sig = dsa.syssign(digest)
puts dsa.sysverify(digest, sig) # => true

#to_derString

Encodes this DSA to its DER encoding.

#export([cipher, password]) ⇒ String #to_pem([cipher, password]) ⇒ String #to_s([cipher, password]) ⇒ String

Alias for #to_s.

#export([cipher, password]) ⇒ String #to_pem([cipher, password]) ⇒ String #to_s([cipher, password]) ⇒ String
Also known as: #export, #to_pem

Encodes this DSA to its PEM encoding.

Parameters

Examples

DSA.to_pem -> aString
DSA.to_pem(cipher, 'mypassword') -> aString

#to_textString

Prints all parameters of key to buffer INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!! Don't use :-)) (I's up to you)