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.

Class Methods

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

Parameters

  • size is an integer representing the desired key size.

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
Instance Methods

Encodes this DSA to its PEM encoding.

Parameters

  • cipher is an OpenSSL::Cipher.

  • password is a string containing your password.

Examples

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

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

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

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

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

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

Sets p, q, g to the DSA instance.

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.digest('SHA1', doc)
sig = dsa.syssign(digest)

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.digest('SHA1', doc)
sig = dsa.syssign(digest)
puts dsa.sysverify(digest, sig) # => true

Encodes this DSA to its DER encoding.

An alias for export

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