Click to Rate and Give Feedback
MSDN
MSDN Library
Security
Cryptography
About Cryptography
 Signature Sample
Signature Sample

This section steps through the signature process. It uses the hash value from the Key Derivation Sample, the MD5 hash of the "124-kelp" string.

This hash value is as follows.

3c 33 c6 cf 4c 8a 51 6d
0b f6 52 03 d1 77 60 60

This example uses "Test Signature" as the description string.

First, the CSP adds this string to the hash object being signed. The description string, "Test Signature," is received by the CSP in Unicode format as the following hexadecimal bytes.

54 00 65 00 73 00 74 00
20 00 53 00 69 00 67 00.
6e 00 61 00 74 00 75 00
18 72 00 65 00

After the description string has been added to the hash, the hash value is as follows.

5e d7 35 84 1e d8 69 53
56 ef 8d 92 d1 81 44 a4

Next, a PKCS signature block is built. Details of the PKCS standards can be found on the RSA Security Standards Web page. The signature block is always the same size as the public key's modulus (64 bytes) and contains the following fields.

FieldBytesDescription
To be signed1 to 16Hash of data to be signed. The size of this field varies depending on the hash algorithm used.

The bytes in the hash value are reversed before they are placed in the encryption block because the operating system formats data in little-endian format, and the encryption block must be built in big-endian format.

Algorithm specifier17 to 34Abstract Syntax Notation One (ASN.1) encoded hash algorithm specifier. The size of this field depends on the hash algorithm used. Note that this data is also reversed. For more information about ASN.1, see the PKCS documentation.
Reserved35Zero value.
Padding36 to 62 Padding data (0xff's). The size of this field is adjusted as necessary so that the signature block's overall length is correct.
Block type63The PKCS block type (0x01).
Reserved64Zero value.

 

The order of this table is reversed from the diagram found in the PKCS documentation because the signature block is built in big-endian on a little-endian computer.

The completed signature block in this example is as follows.

a4 44 81 d1 92 8d ef 56
53 69 d8 1e 84 35 d7 5e
10 04 00 05 05 02 0d f7
86 48 86 2a 08 06 0c 30
20 30 00 ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff 01 00

Next, the block is encrypted with the appropriate private key. This example uses a typical but unspecified private key. This encryption results in a completed digital signature.

57 5c 3e 74 7c 6d 27 b9
2f 7a c0 12 2b a3 1f 74
21 b9 49 ec bc 14 e3 60
4f 6e cf f6 52 b8 45 d6
2b 03 25 31 68 a0 8b 82
66 86 a4 13 1c f5 c1 c3
38 59 aa 08 ae 71 35 30
6b b0 17 ec 04 e4 f9 0e

Send comments about this topic to Microsoft

Build date: 11/16/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker