When a DSS private key is exported, it is in a PRIVATEKEYBLOB format, as follows:
BLOBHEADER blobheader;
DSSPUBKEY dsspubkey;
BYTE p[dsspubkey.bitlen/8];
BYTE q[20];
BYTE g[dsspubkey.bitlen/8];
BYTE X[20];
DSSSEED seedstruct;
The following table describes each public-key component. All values are in little-endian format.
Field | Description |
---|---|
blobheader | A BLOBHEADER structure The bType member must have a value of PRIVATEKEYBLOB. |
dsspubkey | A DSSPUBKEY structure. The magic member must have a value of 0x32535344 (the ASCII encoding of "DSS2"). |
p | The prime modulus P. Must always have the most significant bit of the most significant byte set to 1. |
q | The prime Q. It is 20 bytes in length. The most significant bit of the most significant byte must be set to 1. |
g | The generator G. Must be the same length as p (must be padded with 0x00 bytes if it is less). |
x | The secret exponent X. It must always be 20 bytes in length. If smaller, then it must be padded with 0x00. |
seedstruct | Seed and counter values for verifying primes. |
When calling CryptExportKey the developer can choose whether or not to encrypt the key. The PRIVATEKEYBLOB is encrypted if the hExpKey parameter contains a valid handle to a session key. Everything but the BLOBHEADER portion of the blob is encrypted. Note that the encryption algorithm and encryption key parameters are not stored along with the private-key blob. The application must manage and store this information. If zero is passed for hExpKey, the private key will be exported without encryption.
Warning It is very dangerous to export private keys without encryption, since they are then vulnerable to interception and use by unauthorized entities.