Platform SDK: Cryptography |
Private key BLOBs (type PRIVATEKEYBLOB) are used to store RSA public/private key pairs. They have the following format:
BLOBHEADER blobheader; RSAPUBKEY rsapubkey; BYTE modulus[rsapubkey.bitlen/8]; BYTE prime1[rsapubkey.bitlen/16]; BYTE prime2[rsapubkey.bitlen/16]; BYTE exponent1[rsapubkey.bitlen/16]; BYTE exponent2[rsapubkey.bitlen/16]; BYTE coefficient[rsapubkey.bitlen/16]; BYTE privateExponent[rsapubkey.bitlen/8];
If the key BLOB is encrypted, then 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. It is the responsibility of the application to manage this information.
The following table describes each private key BLOB component. Note that these fields largely correspond to the ones described in section 7.2 of PKCS #1: RSA Encryption Standard.
Field | Description |
---|---|
blobheader | A BLOBHEADER structure as described in a previous section. The bType field must always have a value of PRIVATEKEYBLOB. |
rsapubkey | A RSAPUBKEY structure as described in Public Key BLOBs. The magic field must always have a value of 0x32415352 ("RSA2"). |
modulus | The modulus. This has a value of "prime1 * prime2" and is often known as "n". |
prime1 | Prime number 1, often known as "p". |
prime2 | Prime number 2, often known as "q". |
exponent1 | Exponent 1. This has a numeric value of "d mod (p - 1)". |
exponent2 | Exponent 2. This has a numeric value of "d mod (q - 1)". |
coefficient | Coefficient. This has a numeric value of "(inverse of q) mod p". |
privateExponent | Private exponent, often known as "d". |
The following hex dump shows a sample private key BLOB, generated by the Microsoft Base Cryptographic Provider. This contains a key exchange public/private key pair. Note that this sample contains a public key that is different than the one discussed in Public Key BLOBs.
0x00000000 07 02 00 00 00 a4 00 00 ........ 0x00000008 52 53 41 32 00 02 00 00 RSA2.... 0x00000010 01 00 01 00 6b df 51 ef ....k.Q. 0x00000018 db 6f 10 5c 32 bf 87 1c .o.\2... 0x00000020 d1 4c 24 7e e7 2a 14 10 .L$~.*.. 0x00000028 6d eb 2c d5 8c 0b 95 7b m.,....{ 0x00000030 c7 5d c6 87 12 ea a9 cd .]...... 0x00000038 57 7d 3e cb e9 6a 46 d0 W}>..jF. 0x00000040 e1 ae 2f 86 d9 50 f9 98 ../..P.. 0x00000048 71 dd 39 fc 0e 60 a9 d3 q.9..`.. 0x00000050 f2 38 bb 8d 5d 2c bc 1e .8..],.. 0x00000058 c3 38 fe 00 5e ca cf cd .8..^... 0x00000060 b4 13 89 16 d2 07 bc 9b ........ 0x00000068 e1 20 31 0b 81 28 17 0c . 1..(.. 0x00000070 c7 73 94 ee 67 be 7b 78 .s..g.{x 0x00000078 4e c7 91 73 a8 34 5a 24 N..s.4Z$ 0x00000080 9d 92 0d e8 91 61 24 dc .....a$. 0x00000088 b5 eb df 71 66 dc e1 77 ...qf..w 0x00000090 d4 78 14 98 79 44 b0 19 .x..yD.. 0x00000098 f6 f0 7d 63 cf 62 67 78 ..}c.bgx 0x000000a0 d0 7b 10 ae 6b db 40 b3 .{..k.@. 0x000000a8 b2 eb 2e 9f 31 34 2d cb ....14-. 0x000000b0 bf a2 6a a6 1f e9 03 42 ..j....B 0x000000b8 f2 63 9b b7 33 d0 fe 20 .c..3.. 0x000000c0 83 26 1f 56 a8 24 f5 6d .&.V.$.m 0x000000c8 19 51 a5 92 31 e4 2b bc .Q..1.+. 0x000000d0 11 c8 26 75 a0 51 e9 83 ..&u.Q.. 0x000000d8 ca ee 4b f0 59 eb a4 81 ..K.Y... 0x000000e0 d6 1f 49 42 2b 75 89 a7 ..IB+u.. 0x000000e8 9f 84 7f 1f c3 8f 70 b6 ......p. 0x000000f0 7e 06 5e 8b c9 53 65 80 ~.^..Se. 0x000000f8 b7 16 f2 5e 5e de 0b 57 ...^^..W 0x00000100 47 43 86 85 8a fb 37 ac GC....7. 0x00000108 66 34 ba 09 1a b1 21 0b f4....!. 0x00000110 aa fa 6c b7 75 a7 3e 23 ..l.u.># 0x00000118 18 58 95 90 b5 29 a4 1e .X...).. 0x00000120 15 76 52 56 bb 3d 6b 1d .vRV.=k. 0x00000128 2a d1 9f 5c 8a c0 55 ea *..\..U. 0x00000130 c3 29 a2 1e .)..
Notice that the BLOBHEADER and RSAPUBKEY structures have been assigned the following values:
blobheader.bType = PRIVATEKEYBLOB; // 0x07 blobheader.bVersion = CUR_BLOB_VERSION; // 0x02 blobheader.reserved = 0; // 0x0000 blobheader.aiKeyAlg = CALG_RSA_KEYX; // 0x0000a400 rsapubkey.magic = 0x32415352; // "RSA2" rsapubkey.bitlen = 512; // 0x00000200 rsapubkey.pubexp = 65537; // 0x00010001
The following table shows the numeric values of each of the large numeric fields contained by the sample private key BLOB. As with all of the numbers in the public and private key BLOBs, these are in little-endian byte order.
Field name | Value |
---|---|
modulus | 6b df 51 ef db 6f 10 5c 32 bf 87 1c d1 4c 24 7e |
prime1 | 5d 2c bc 1e c3 38 fe 00 5e ca cf cd b4 13 89 16 |
prime2 | 67 be 7b 78 4e c7 91 73 a8 34 5a 24 9d 92 0d e8 |
exponent1 | 79 44 b0 19 f6 f0 7d 63 cf 62 67 78 d0 7b 10 ae |
exponent2 | 1f e9 03 42 f2 63 9b b7 33 d0 fe 20 83 26 1f 56 |
coefficient | a0 51 e9 83 ca ee 4b f0 59 eb a4 81 d6 1f 49 42 |
+privateExponent | c9 53 65 80 b7 16 f2 5e 5e de 0b 57 47 43 86 85 |