A
Allen Holman
I am attempting to write software using the compact
framework that duplicates on a PDA the file signing we
are using on PCs.
So far, I have been able to write software that computes
an identical 20 byte SHA-1 hash on either the PC or PDA.
However, I have been unable to sign the hash and get
identical results. One problem is that I need to import
my private key to the PDA. I have read an written code
to implement the techniques described in Q228786 and this
allows me to import the public / private key pair, and I
have set the key length so both the PC and PDA return 128
bytes of signed data. The problem is that the byte
streams are not identical.
One problem may be mapping the key from one system to the
other. On the PC, I can export the key as an
RSAParameters object. On the PDA side I have to use a
PRIVATEKEYBLOB class to import the key. The two objects
have different variable names and I have mapped them as
follows
RSAParameter PRIVATEKEYBLOB
D -------------- privateExponent
dP ------------- exponent1
dQ ------------- exponent2
IQ ------------- coefficient
Modulus -------- modulus
P -------------- prime1
Q -------------- prime2
This could be a source of my problem if this is not
correct.
The code I am using to import the key follows:
if (CryptExportKey(hPrivateKey,(IntPtr)0, PRIVATEKEYBLOB,
0, bData, ref iLgth))
{
CryptDestroyKey(hPrivateKey);
hPrivateKey = (IntPtr)0;
CreatePrivateExponentOneKey(bData);
CryptImportKey(hProvider, bData, iLgth, (IntPtr)0, 0, ref
hPrivateKey);
CryptDestroyKey(hPrivateKey);
hPrivateKey = (IntPtr)0;
SetMDIPDAPrivateKey(bData,iLgth);
CryptImportKey(hProvider, bData, iLgth, (IntPtr)0,
CRYPT_EXPORTABLE, ref hPrivateKey);
CryptExportKey(hPrivateKey,(IntPtr)0, PRIVATEKEYBLOB, 0,
bData, ref iLgth);
}
The code to sign the hash is as follows:
CryptSignHash(hHash, AT_SIGNATURE, null, 0, bSignature,
ref iLgth);
Any help in getting this to work will be appreciated.
Allen Holman
framework that duplicates on a PDA the file signing we
are using on PCs.
So far, I have been able to write software that computes
an identical 20 byte SHA-1 hash on either the PC or PDA.
However, I have been unable to sign the hash and get
identical results. One problem is that I need to import
my private key to the PDA. I have read an written code
to implement the techniques described in Q228786 and this
allows me to import the public / private key pair, and I
have set the key length so both the PC and PDA return 128
bytes of signed data. The problem is that the byte
streams are not identical.
One problem may be mapping the key from one system to the
other. On the PC, I can export the key as an
RSAParameters object. On the PDA side I have to use a
PRIVATEKEYBLOB class to import the key. The two objects
have different variable names and I have mapped them as
follows
RSAParameter PRIVATEKEYBLOB
D -------------- privateExponent
dP ------------- exponent1
dQ ------------- exponent2
IQ ------------- coefficient
Modulus -------- modulus
P -------------- prime1
Q -------------- prime2
This could be a source of my problem if this is not
correct.
The code I am using to import the key follows:
if (CryptExportKey(hPrivateKey,(IntPtr)0, PRIVATEKEYBLOB,
0, bData, ref iLgth))
{
CryptDestroyKey(hPrivateKey);
hPrivateKey = (IntPtr)0;
CreatePrivateExponentOneKey(bData);
CryptImportKey(hProvider, bData, iLgth, (IntPtr)0, 0, ref
hPrivateKey);
CryptDestroyKey(hPrivateKey);
hPrivateKey = (IntPtr)0;
SetMDIPDAPrivateKey(bData,iLgth);
CryptImportKey(hProvider, bData, iLgth, (IntPtr)0,
CRYPT_EXPORTABLE, ref hPrivateKey);
CryptExportKey(hPrivateKey,(IntPtr)0, PRIVATEKEYBLOB, 0,
bData, ref iLgth);
}
The code to sign the hash is as follows:
CryptSignHash(hHash, AT_SIGNATURE, null, 0, bSignature,
ref iLgth);
Any help in getting this to work will be appreciated.
Allen Holman