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
DSAinstance by generating a private/public key pair from scratch. -
.new([size | string [, pass]) ⇒ DSA
constructor
Creates a new
DSAinstance by reading an existing key fromstring.
PKey - Inherited
| .new | Because PKey is an abstract class, actually calling this method explicitly will raise a |
Instance Attribute Summary
-
#private? ⇒ Boolean
readonly
Indicates whether this
DSAinstance has a private key associated with it or not. -
#public? ⇒ Boolean
readonly
Indicates whether this
DSAinstance has a public key associated with it or not.
Instance Method Summary
-
#export([cipher, password]) ⇒ String
Alias for #to_s.
-
#params ⇒ Hash
Stores all parameters of key to the hash INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!! Don't use :-)) (I's up to you).
-
#public_key ⇒ DSA
Returns a new
DSAinstance that carries just the public key information. -
#syssign(string) ⇒ String
Computes and returns the
DSAsignature ofstring, wherestringis expected to be an already-computed message digest of the original input data. -
#sysverify(digest, sig) ⇒ Boolean
Verifies whether the signature is valid given the message digest input.
-
#to_der ⇒ String
Encodes this
DSAto its DER encoding. -
#to_pem([cipher, password]) ⇒ String
Alias for #to_s.
-
#to_s([cipher, password]) ⇒ String
(also: #export, #to_pem)
Encodes this
DSAto its PEM encoding. -
#to_text ⇒ String
Prints all parameters of key to buffer INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!! Don't use :-)) (I's up to you).
PKey - Inherited
| #sign | To sign the |
| #verify | To verify the |
Constructor Details
.new([size | string [, pass]) ⇒ DSA
Creates a new DSA instance by reading an existing key from string.
Parameters
-
sizeis an integer representing the desired key size. -
stringcontains a DER or PEM encoded key. -
passis 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
-
sizeis 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
String
#to_pem([cipher, password]) ⇒ String
#to_s([cipher, password]) ⇒ String
Alias for #to_s.
#params ⇒ Hash
Stores all parameters of key to the hash INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!! Don't use :-)) (I's up to you)
#public_key ⇒ DSA
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
#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
-
stringis 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
-
digestis a message digest of the original input data to be signed -
sigis aDSAsignature 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_der ⇒ String
Encodes this DSA to its DER encoding.
#export([cipher, password]) ⇒ String
#to_pem([cipher, password]) ⇒ String
#to_s([cipher, password]) ⇒ String
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
String
#to_pem([cipher, password]) ⇒ String
#to_s([cipher, password]) ⇒ String
Encodes this DSA to its PEM encoding.
Parameters
-
cipheris an ::OpenSSL::Cipher. -
passwordis a string containing your password.
Examples
DSA.to_pem -> aString
DSA.to_pem(cipher, 'mypassword') -> aString
#to_text ⇒ String
Prints all parameters of key to buffer INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!! Don't use :-)) (I's up to you)