4

Is it acceptable that I cache HCRYPTPROV returned by CryptAcquireContext when my app starts and reuse it for later cryptographic calls (i.e. calculating HMACs and encrypting/AES) in a form as such:

HCRYPTPROV global_hProvSingleton = NULL;

HCRYPTPROV getCryptoContextSingleton()
{
    if(!global_hProvSingleton)
    {
        //Do it only once
        ::CryptAcquireContext(&global_hProvSingleton, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET);
    }

    return global_hProvSingleton;
}
too honest for this site
  • 12,050
  • 4
  • 30
  • 52
c00000fd
  • 20,994
  • 29
  • 177
  • 400

0 Answers0