Dsa JavaScript Reference Documentation

Dsa

Current Version: 11.4.0

The Digital Signature Algorithm (DSA) is a United States Federal Government standard or FIPS for digital signatures. It was proposed by the National Institute of Standards and Technology (NIST) in August 1991 for use in their Digital Signature Standard (DSS).

Object Creation

Note: This is intended for running within a Chilkat.Js embedded JavaScript engine.

var obj = new CkDsa();

Properties

DebugLogFilePath
DebugLogFilePath
· string

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
GroupSize
GroupSize
· int

The group size (in bits) to be used in DSA key generation. The default value is 160 and corresponds to the fact that SHA-1 is used in signature generation. This property setting should not be changed. It exists for future expansion when additional underlying hash algorithms are supported.

top
HexG
HexG
· string, read-only

The G part of a public or private DSA key returned as a hex-encoded SSH1-format bignum. The G is the generator. DSA key params consist of G, P, and Q.

top
HexP
HexP
· string, read-only

The P part of a public or private DSA key returned as a hex-encoded SSH1-format bignum. The P is a large prime. DSA key params consist of G, P, and Q.

top
HexQ
HexQ
· string, read-only

The Q part of a public or private DSA key returned as a hex-encoded SSH1-format bignum. DSA key params consist of G, P, and Q.

top
HexX
HexX
· string, read-only

The X part of a DSA private key returned as a hex-encoded SSH1-format bignum.

top
HexY
HexY
· string, read-only

The Y part of a DSA public key returned as a hex-encoded SSH1-format bignum. (The Y value is also accessible w/ a private key, but the X value is not available in a DSA public key.)

top
LastErrorHtml
LastErrorHtml
· string, read-only

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
LastErrorText
· string, read-only

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
LastErrorXml
· string, read-only

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
LastMethodSuccess
· boolean

Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
UncommonOptions
UncommonOptions
· string
Introduced in version 9.5.0.90

This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.

top
VerboseLogging
VerboseLogging
· boolean

If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
Version
· string, read-only

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

FromDerBd
var success = FromDerBd(bd);
· return: boolean; true for success, false for failure
· bd: CkBinData
Introduced in version 11.0.0

Loads a DSA private key from DER contained in bd.

Returns true for success, false for failure.

top
FromDerFile
var success = FromDerFile(path);
· return: boolean; true for success, false for failure
· path: string

Loads a DSA private key from a DER-encoded file.

Returns true for success, false for failure.

More Information and Examples
top
FromEncryptedPem
var success = FromEncryptedPem(password, pemData);
· return: boolean; true for success, false for failure
· password: string
· pemData: string

Loads a DSA private key from an in-memory encrypted PEM-formatted string. If the PEM passed to this method is unencrypted, the password is ignored and the PEM is simply loaded.

Returns true for success, false for failure.

top
FromPem
var success = FromPem(pemData);
· return: boolean; true for success, false for failure
· pemData: string

Loads a DSA private key from an in-memory unencrypted PEM-formatted string.

Returns true for success, false for failure.

More Information and Examples
top
FromPublicDerBd
var success = FromPublicDerBd(bd);
· return: boolean; true for success, false for failure
· bd: CkBinData
Introduced in version 11.0.0

Loads a DSA public key from an DER-encoded data in bd.

Returns true for success, false for failure.

top
FromPublicDerFile
var success = FromPublicDerFile(path);
· return: boolean; true for success, false for failure
· path: string

Loads a DSA public key from a DER-encoded file.

Returns true for success, false for failure.

top
FromPublicPem
var success = FromPublicPem(pemData);
· return: boolean; true for success, false for failure
· pemData: string

Loads a DSA public-key from an in-memory PEM string.

Returns true for success, false for failure.

top
FromXml
var success = FromXml(xmlKey);
· return: boolean; true for success, false for failure
· xmlKey: string

Loads a DSA public or private key from an in-memory XML string.

Returns true for success, false for failure.

top
GenKey
var success = GenKey(numBits);
· return: boolean; true for success, false for failure
· numBits: int

Generates a new DSA key that is numBits bits in length. The numBits should be at least 1024 bits and a multiple of 64. Typical values are 1024 and 2048. The newly generated key may be exported by calling one of the To* methods.

Returns true for success, false for failure.

More Information and Examples
top
GenKey2
var success = GenKey2(keyLenBits, modLenBits);
· return: boolean; true for success, false for failure
· keyLenBits: int
· modLenBits: int
Introduced in version 9.5.0.90

Generates a new DSA key that is keyLenBits bits in length with a modulus of size modLenBits bits. The keyLenBits should be at least 1024 bits and a multiple of 64. FIPS 186-4 specifies the key length (bits) and modulus size (bits) to have one of the values: (1024, 160), (2048, 224), (2048, 256), or (3072, 256).

Returns true for success, false for failure.

top
GenKeyFromParamsDerBd
var success = GenKeyFromParamsDerBd(bd);
· return: boolean; true for success, false for failure
· bd: CkBinData
Introduced in version 11.0.0

Generates a new DSA key using the binary OpenSSL formatted DER parameters in bd. The key can be exported using any of the To* methods.

Returns true for success, false for failure.

top
GenKeyFromParamsDerFile
var success = GenKeyFromParamsDerFile(path);
· return: boolean; true for success, false for failure
· path: string

Generates a new DSA key from a DER-format parameters file created by OpenSSL. An example of using OpenSSL to generate DSA parameters in DER format is:

openssl dsaparam -outform DER 1024 < seedData.xml > dsaparam.der
The newly generated key may be exported by calling one of the To* methods.

Returns true for success, false for failure.

top
GenKeyFromParamsPem
var success = GenKeyFromParamsPem(pem);
· return: boolean; true for success, false for failure
· pem: string

Generates a new DSA key from parameters (PEM formatted string) created by OpenSSL. The newly generated key may be exported by calling one of the To* methods.

Returns true for success, false for failure.

top
GenKeyFromParamsPemFile
var success = GenKeyFromParamsPemFile(path);
· return: boolean; true for success, false for failure
· path: string

Generates a new DSA key from a PEM parameters file created by OpenSSL. The newly generated key may be exported by calling one of the To* methods.

OpenSSL provides the ability to generate DSA key parameters. For example:

openssl dsaparam 1024 < seedData.txt > dsaparam.pem

Here is a sample DSA parameters PEM:

-----BEGIN DSA PARAMETERS-----
MIIBHgKBgQCXIAx4XzLVZ5ZqOFzdsYWVyH/6E/mVPw4TgMZS6Wxajnbdn1/CUBzE
RWTUp8SguTSDpjC1Q/nyno0G6Q96VoW+PUXv8qUph8vbSaEdsjYO/8jSfzkGfvsa
cucr1ythfNyk63aZAKzxeutOmsVe77l6pZI96ROjWF5iizuUB4WgmwIVANxM70wH
8iPPYVzPZqtXCB66I2SnAoGAIbW2VYRjRdoA7trJgmnfWakghKwV1WyaYrotqeDE
07/dipp0cNuY0IAJgSmqLHlAkNa2ZNI/c1mNxcwhYzZrnn8CXIqrYmtI33w0PYCx
KHPqj7puhddFwYS/rFiyWAN0jtCMHlfCVzFGbSzach5QQraPV9YApJXy+ORJ8VPU
/zo=
-----END DSA PARAMETERS-----

Returns true for success, false for failure.

top
GenKeyFromPQG
var success = GenKeyFromPQG(pHex, qHex, gHex);
· return: boolean; true for success, false for failure
· pHex: string
· qHex: string
· gHex: string
Introduced in version 9.5.0.90

Generates a new DSA key from pre-chosen P, Q, and G params.

Returns true for success, false for failure.

top
GetEncodedHash
var strVal = GetEncodedHash(encoding);
· return: string
· encoding: string

Returns the bytes of the Hash property as a hex or base64 encoded string. The encoding should be set to either hex or base64.

Returns null on failure

top
GetEncodedSignature
var strVal = GetEncodedSignature(encoding);
· return: string
· encoding: string

Returns the bytes of the Signature property as a hex or base64 encoded string. The encoding should be set to either hex or base64. The Signature property is set when SignHash is called.

Returns null on failure

top
LoadText
var strVal = LoadText(path);
· return: string
· path: string

Convenience method to load the entire contents of a text file into a string. It is assumed that the text contains ANSI encoded character data.

Returns null on failure

top
SaveText
var success = SaveText(strToSave, path);
· return: boolean; true for success, false for failure
· strToSave: string
· path: string

Convenience method to save a string to a text file. The text is saved using the ANSI character encoding.

Returns true for success, false for failure.

top
SetEncodedHash
var success = SetEncodedHash(encoding, encodedHash);
· return: boolean; true for success, false for failure
· encoding: string
· encodedHash: string

Provides a way to set the Hash property by passing an encoded string. The encoding can be hex or base64. The encodedHash contains the encoded bytes of the hash that will be signed or verified via the SignHash and Verify methods.

Returns true for success, false for failure.

top
SetEncodedSignature
var success = SetEncodedSignature(encoding, encodedSig);
· return: boolean; true for success, false for failure
· encoding: string
· encodedSig: string

Sets the bytes of the Signature property. (The signature must be specified prior to calling the Verify method.) This method allows for the signature to be set via a hex or base64 encoded string. The encoding should be set to either hex or base64.

Returns true for success, false for failure.

top
SetEncodedSignatureRS
var success = SetEncodedSignatureRS(encoding, encodedR, encodedS);
· return: boolean; true for success, false for failure
· encoding: string
· encodedR: string
· encodedS: string

Sets the bytes of the Signature property by providing the R and S values in encoded form. (The signature must be specified prior to calling the Verify method.) The R and S values may be set via a hex or base64 encoded string. The encoding should be set to either hex or base64.

Returns true for success, false for failure.

top
SetKeyExplicit
var success = SetKeyExplicit(groupSizeInBytes, pHex, qHex, gHex, xHex);
· return: boolean; true for success, false for failure
· groupSizeInBytes: int
· pHex: string
· qHex: string
· gHex: string
· xHex: string

Sets the DSA object's private key from explicitly provided pHex, qHex, gHex, and xHex values. The groupSizeInBytes specifies the group size (in bytes). It is typically equal to 20, which is the length of the underlying hash function (SHA-1) for signing. The pHex, qHex, gHex, and xHex values are hex-encoded SSH1-format bignums.

Returns true for success, false for failure.

top
SetPubKeyExplicit
var success = SetPubKeyExplicit(groupSizeInBytes, pHex, qHex, gHex, yHex);
· return: boolean; true for success, false for failure
· groupSizeInBytes: int
· pHex: string
· qHex: string
· gHex: string
· yHex: string

Sets the DSA object's private key from explicitly provided pHex, qHex, gHex, and yHex values. The groupSizeInBytes specifies the group size (in bytes). It is typically equal to 20, which is the length of the underlying hash function (SHA-1) for signing. The pHex, qHex, gHex, and yHex values are hex-encoded SSH1-format bignums.

Returns true for success, false for failure.

top
SignHash
var success = SignHash();
· return: boolean; true for success, false for failure

Signs a hash using the digital signature algorithm. Before calling this method, set the hash to be signed by either calling SetEncodedHash or by setting the Hash property. If SignHash returns true, the signature may be retrieved by either calling GetEncodedHash, or by accessing the Signature property.

Returns true for success, false for failure.

More Information and Examples
top
ToDerBd
var success = ToDerBd(bd);
· return: boolean; true for success, false for failure
· bd: CkBinData
Introduced in version 11.0.0

Writes the DSA private key to DER-encoded bytes in the bd.

Returns true for success, false for failure.

top
ToDerFile
var success = ToDerFile(path);
· return: boolean; true for success, false for failure
· path: string

Writes the DSA private key to a DER-format file.

Returns true for success, false for failure.

More Information and Examples
top
ToEncryptedPem
var strVal = ToEncryptedPem(password);
· return: string
· password: string

Writes the DSA private key to an in-memory encrypted PEM string.

Returns null on failure

top
ToPem
var strVal = ToPem();
· return: string

Writes the DSA private key to an in-memory PEM string.

Returns null on failure

More Information and Examples
top
ToPublicDerBd
var success = ToPublicDerBd(bd);
· return: boolean; true for success, false for failure
· bd: CkBinData
Introduced in version 11.0.0

Writes the DSA public key to a DER-encoded bytes in bd.

Returns true for success, false for failure.

top
ToPublicDerFile
var success = ToPublicDerFile(path);
· return: boolean; true for success, false for failure
· path: string

Writes the DSA public key to a DER-format file.

Returns true for success, false for failure.

More Information and Examples
top
ToPublicPem
var strVal = ToPublicPem();
· return: string

Writes the DSA public key to an in-memory PEM string.

Returns null on failure

More Information and Examples
top
ToXml
var strVal = ToXml(bPublicOnly);
· return: string
· bPublicOnly: boolean

Writes the DSA private or public key to an in-memory XML string. The bPublicOnly determines whether the public or private key is written.

Returns null on failure

More Information and Examples
top
Verify
var success = Verify();
· return: boolean; true for success, false for failure

Verifies a DSA signature. The Hash and Signature properties must be set prior to calling this method. (These properties may also be set via the SetEncodedHash and SetEncodedSignature methods.)

Returns true for success, false for failure.

top
VerifyKey
var boolVal = VerifyKey();
· return: boolean

Verifies that the public or private key contained in the calling Dsa object is valid. Returns true if valid, otherwise returns false.

More Information and Examples
top