Home   Index   About
Ultimate Pack


Custom Search
Signature Sample

This section steps through the signature process. This sample starts with the hash value used in the previous sample; that is, an MD5 hash of the "1134-kelp" string. This hash value is shown below:

0x00000000 73 40 e6 e2 74 b8 ea 39 s@..t..9

0x00000008 93 95 aa 29 d6 38 b5 2a ...).8.*

This example assumes that the application specified "Test Signature" as the description string. The first thing that the CSP does is to add this string to the hash object that is being signed. Of course, the description string is received by the CSP in Unicode format, as shown below:

0x00000000 54 00 65 00 73 00 74 00 T.e.s.t.

0x00000008 20 00 53 00 69 00 67 00 .S.i.g.

0x00000010 6e 00 61 00 74 00 75 00 n.a.t.u.

0x00000018 72 00 65 00 r.e.

Once the description string has been hashed in, the hash value is extracted:

0x00000000 a8 2b df c2 c9 f1 bb 62 .+.....b

0x00000008 38 78 d4 60 fa ce 5c 2a 8x.`..\*

The next step is building a PKCS signature block. This is always the same size as the public key's modulus (64 bytes) and contains the following fields:

Bytes
Description
16
Hash of data to be signed. The size of this field will vary, depending on the hash algorithm used.
As you can see from comparing the hex dump of the hash value above and the hex dump of the following encryption block, the bytes in the hash value are reversed before they are placed in the encryption block. This is because Windows NT formats data in little endian format, and the encryption block must be built in big endian format.
18
ASN.1 encoded hash algorithm specifier. The size of this field will vary, depending on the hash algorithm used. Note that this data is also reversed.
A description of ASN.1 is beyond the scope of this document, but a table of common ASN.1 strings is provided in the next section. For more information on ASN.1, see the PKCS documentation.

Zero value.
27
Padding data (0xff's). The size of this field is adjusted as necessary so that the signature block's overall length is correct.

The PKCS block type (0x01).

Zero value.

You may notice that the order of this table is reversed from the diagram found in the PKCS documentation. This is because we are building the signature block in big endian on a little endian computer.

Once the signature block has been built, it looks something like this:

0x00000000 2a 5c ce fa 60 d4 78 38 *\..`.x8

0x00000008 62 bb f1 c9 c2 df 2b a8 b.....+.

0x00000010 10 04 00 05 05 02 0d f7 ........

0x00000018 86 48 86 2a 08 06 0c 30 .H.*...0

0x00000020 20 30 00 ff ff ff ff ff 0......

0x00000028 ff ff ff ff ff ff ff ff ........

0x00000030 ff ff ff ff ff ff ff ff ........

0x00000038 ff ff ff ff ff ff 01 00 ........

The next step is to encrypt the block with the appropriate private key. In this example, the private key used is the one corresponding to the public key used in the previous section Public Key Blob Format. This results in a completed digital signature:

0x00000000 64 f6 46 3a 97 2e 83 38 d.F:...8

0x00000008 09 57 43 cb ca 41 59 0d .WC..AY.

0x00000010 03 35 d6 e4 36 6f 2c fc .5..6o,.

0x00000018 63 43 95 c4 fd e2 c4 ed cC......

0x00000020 06 da 9a 21 98 fc 0a 6e ...!...n

0x00000028 3f 1c ad 3a db 7c 83 2f ?..:.|./

0x00000030 14 d0 58 80 02 df dc 96 ..X.....

0x00000038 70 09 00 e3 5b bd 2b 45 p...[.+E


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2012 Free Tech Secrets ;) greatis just4fun network just4fun