CALG_RSA_KEYX algorithm?



Hi,

I'm encrypting my session key using CryptEncrypt API with a 1024-bit
public key. The problem is, I want to decrypt the session key in
another platform but I don't know how CALG_RSA_KEYX encrypts it in the
first place. Is there something I can do to implement the same
algorithm (maybe a standart one?) for example in PHP? Or should I use
an open-source rsa C library for this purpose instead of CryptoAPI?

Here is the code I use for encrypting:

HCRYPTPROV hCryptProv;
HCRYPTKEY hKey;

if (!CryptAcquireContext(&hCryptProv, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
// Error
_tprintf(_T("CryptAcquireContext error 0x%x\n"),
GetLastError());
goto err;
}

FILE * fp = fopen("publickey.txt", "rb+");

if(fp == NULL) goto err;

long PublicLen = filelength(fileno(fp));

void * PublicKey = malloc(PublicLen);

fread(PublicKey, PublicLen, 1, fp);

fclose(fp);

if (!CryptImportKey(hCryptProv, PublicKey, PublicLen, 0,
0, &hKey))
{
// Error
_tprintf(_T("CryptImportKey error 0x%x\n"),
GetLastError());
goto err;
}

free(PublicKey);

long EncryptedLen = 0;
char * pbData = (char *) calloc(1, 54);
sprintf(pbData, "SESSIONKEY"); // example
long datalen = strlen(pbData);

if (!CryptEncrypt(hKey, 0, TRUE, 0, NULL, &EncryptedLen,
0))
{
// Error
_tprintf(_T("CryptEncrypt1 error 0x%x\n"),
GetLastError());
goto err;
}

if (!(pbData = (char *) realloc(pbData, EncryptedLen)))
{
// Error
_tprintf(_T("malloc error 0x%x\n"), GetLastError());
goto err;
}

if (!CryptEncrypt(hKey, 0, TRUE, 0, pbData, &datalen,
EncryptedLen))
{
// Error
_tprintf(_T("CryptEncrypt2 error 0x%x\n"),
GetLastError());
goto err;
}

Thanks in advance...
.



Relevant Pages

  • RE: CALG_RSA_KEYX algorithm?
    ... CALG_RSA_KEYX is used to encrypt the SESSION Key. ... if (!CryptImportKey(hCryptProv, PublicKey, PublicLen, 0, ...
    (microsoft.public.platformsdk.security)
  • Re: CryptExportKey - length of exported session key depends on key container history
    ... Create 40 bit CALG_RC4 exportable session key using CryptGenKey. ... A related thing is what happens if the key container is created using ... blob is always the PublicKey size + 12 bytes for any header. ... Your default provider is a basic provider where the length of a public key ...
    (microsoft.public.platformsdk.security)