Equivalent of Rfc2898DeriveBytes in C/C++ RRS feed

  • Question

  • Hi there,

    i'm trying to convert some C# code that uses the Rfc2898DeriveBytes class.

    I'm wondering which is an equivalent manner to obtain the same sequence of bytes in C/C++ for a Win32 platform.


    Wednesday, October 9, 2013 2:57 PM


All replies

  • Is it using the OpenSSL library?

    I was looking for a WinCrypt solution; i will need to port to WinCE ..


    Wednesday, October 9, 2013 3:19 PM
  • Some says they've implemented it using basic CryptoAPI methods in this thread: https://groups.google.com/forum/#!topic/microsoft.public.security.crypto/yR-7z-G_NCk

    • Marked as answer by SteMMo Friday, October 11, 2013 11:01 AM
    Wednesday, October 9, 2013 3:25 PM
  • Ok!!

    I (little) modified the above code and now i'm able to generate two keys.

    Now i need the equivalent of the RijndaelManaged class ..


    Thursday, October 10, 2013 10:06 AM
  • My attempt is with the following code:

    void Rijndael( BYTE* data, const BYTE* key, BYTE* iv) 
    	// Create the crypto provider context.
    	HCRYPTPROV hProvider = NULL;
    	if (!CryptAcquireContext(&hProvider,
    			         NULL,				// pszContainer = no named container
    			         NULL,				// pszProvider = default provider
    			         PROV_RSA_FULL,	// PROV_RSA_AES,
    		printf("Unable to create crypto provider context.");
    	// Construct the blob necessary for the key generation.
    	typedef struct {
    		BLOBHEADER	header;
    		DWORD		key_length;
    		BYTE		key_bytes[32];
    	} AesBlob;
    	AesBlob aes_blob;
    	aes_blob.header.bType = PLAINTEXTKEYBLOB;
    	aes_blob.header.bVersion = CUR_BLOB_VERSION;
    	aes_blob.header.reserved = 0;
    	aes_blob.header.aiKeyAlg = CALG_AES_256;
    	aes_blob.key_length = 32;
    	memcpy(aes_blob.key_bytes, key, 32);
    	// Create the crypto key struct that Windows needs.
    	if (!CryptImportKey(	hProvider,
    				(BYTE*)&aes_blob,	sizeof(AesBlob),
    				NULL,				// hPubKey = not encrypted
    				0,					// dwFlags
    		printf("Unable to create crypto key. err=0x%x\n", GetLastError());
    		goto end_AESCrypt;

    but i always receive error 0x8009008


    Thursday, October 10, 2013 2:15 PM
  • I restored the PROV_RSA_AES and the function returns a good value!!


    Thursday, October 10, 2013 4:03 PM
  • Hi SteMMo,

    Does David Lowndes's replies resolve your issue? If so, please mark the solution as answer, and more callers could find the answer quickly.

    Thanks for your understanding!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 11, 2013 3:16 AM