Problem with CryptoAPI
From: Seb (fiix_at_mime.univ-paris8.fr)
Date: 08/24/04
- Next message: Adam Kodeda [MS]: "Re: USB Memory Stick on WinCE device"
- Previous message: metin.koc_at_t-tronics.com.tr: "How to Develop a Boot Loader - A Compilation Problem"
- Next in thread: Igor Dvorkin [MS]: "Re: Problem with CryptoAPI"
- Reply: Igor Dvorkin [MS]: "Re: Problem with CryptoAPI"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Aug 2004 17:29:57 +0200
Hello,
I have read the documentation about CryptoAPI and i test the samples but
it don't work.
I would like create a key, encrypt and decrypt a file with this key.
But it's impossible to me to create a key, my source code is following:
I call Init() and after GenerateRandomKey() but CryptGetUserKey return
failed 0x8009000d
Where is the pb ?
DWORD CMsCrypto::GenerateRandomKey()
{
if (!CryptGenKey(m_hProv, CALG_RC2, CRYPT_EXPORTABLE, &m_hKey))
{
CString szError;
szError.Format(_T("Error 0x%x during CryptGenKey!\n"), GetLastError ());
AfxMessageBox(szError);
return E_FAIL;
}
// Get the handle to the key exchange public key.
if (!CryptGetUserKey(m_hProv, AT_KEYEXCHANGE, &m_hXchgKey))
{
CString szError;
szError.Format(_T("Error 0x%x during CryptGetUserKey!\n"),
GetLastError());
AfxMessageBox(szError);
return E_FAIL;
}
return NO_ERROR;
}
void CMsCrypto::Init()
{
HCRYPTPROV hProv;
DWORD dwFlags = CRYPT_VERIFYCONTEXT;
static TCHAR *szRealProvider=TEXT("Microsoft Enhanced Cryptographic
Provider v1.0");
static TCHAR *szWeakProvider=TEXT("Microsoft Base Cryptographic
Provider v1.0");
if (CryptAcquireContext(&m_hProv, NULL, szRealProvider, PROV_RSA_FULL,
dwFlags)
|| (GetLastError() == NTE_BAD_KEYSET
&& CryptAcquireContext(&m_hProv, NULL, szRealProvider,
PROV_RSA_FULL,CRYPT_NEWKEYSET)
))
{
m_lpszWhichCSP = szRealProvider;
} else {
m_lpszWhichCSP = szWeakProvider;
}
}
- Next message: Adam Kodeda [MS]: "Re: USB Memory Stick on WinCE device"
- Previous message: metin.koc_at_t-tronics.com.tr: "How to Develop a Boot Loader - A Compilation Problem"
- Next in thread: Igor Dvorkin [MS]: "Re: Problem with CryptoAPI"
- Reply: Igor Dvorkin [MS]: "Re: Problem with CryptoAPI"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|