This is my C# signature:
[DllImport ("Advapi32.dll")] //or [DllImport ("coredll.dll")] for Compact
Framework
public static extern bool CryptImportKey(IntPtr hProv, byte[] pbKeyData,
UInt32 dwDataLen, IntPtr hPubKey, UInt32 dwFlags, ref IntPtr hKey);
My code is as follows:
pbPublicKey = ... (valid byte[]array representing a public key blob. This
was obtained from a CERT_INFO structure)
IntPtr hPublicKey = IntPtr.Zero;
result = CryptImportKey(hProv, pbPublicKey, (UInt32) pbPublicKey.Length,
IntPtr.Zero, 0, ref hPublicKey);
if( result == false)
{
lastError = GetLastError();
MessageBox.Show("CryptImportKey failed, last error " +
lastError.ToString());
}
The error I get is 126, Module not found. I am pretty sure that is a memory
issue, but I can't see what the problem is. Through debugging, I have
verified that all the parameters passed to CryptImportKey are correct. hProv
is a valid handle and pbPublicKey is a byte array with length 140. Is there
anything I'm missing??? I have been struggling with this for awhile, so I'd
really appreciate any suggestions!!!!
Thanks, Mita
"mita patel" <m2p...@engmail.uwaterloo.ca> wrote in message
news:eyHQmDduCHA.2568@TK2MSFTNGP12...
"mita patel" <m2p...@engmail.uwaterloo.ca> wrote in message
news:eyHQmDduCHA.2568@TK2MSFTNGP12...
My goal is to write a client/server app which allows the client to sign data
which is verified on the server side.
On the client side (which uses the Compact Framework), I call the following
functions:
1.CertOpenStore - which returns a handle to the "MY" certificate store
2.CertEnumCertificatesInStore - this is how i obtain the desired certificate
3.CryptAcquireCertificatePrivateKey
4.CryptCreateHash
5.CryptHashData
6.CryptSignHash
7.SendData(data, signature, publicKeyBlob) - this is the web service API
On the server side, SendData(data, signature, publicKeyBlob) calls the
following:
1.CryptAcquireContext - this gets the default CSP
2.CryptImportKey - *** this is where i'm stuck *****
3.CryptCreateHash
4.CryptHashData
5.CryptVerifySignature
Right now, I do not have a server side in place. I am just trying to get
all the functions to work on the client side. So SendData() is called
locally on the client. I am trying to import the key obtained from the
certificate into the default CSP, since that is what will be done on the
server. For some reason, CryptImportKey fails even though i'm passing it a
valid public key blob that was obtained from a certificate (returns error
NTE_BAD_VER). I tried running the code in a .NET Windows App (as opposed to
the CF) and the error that is returned is ERROR_MOD_NOT_FOUND.
Please let me know if you have any more questions. Thanks!
Mita
"Alex Feinman" <publi...@alexfeinman.com> wrote in message
news:#Hp4wRduCHA.2596@TK2MSFTNGP12...
David Stucki
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.