我需要使用MS CryptoAPI加密私有RSA密钥以满足此标头(生成的IV将会有所不同,但这与问题无关):
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,E7AE93C9E49184EA
我不确定以下过程是否正确(为简洁省略了内存分配和错误检查):
HCRYPTKEY hSecretKey = 0;
HCRYPTHASH hHash = 0;
CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash);
CryptHashData(hHash, (LPBYTE)pwd, pwdSize, 0);
CryptDeriveKey(hProv, CALG_3DES, hHash, 0, &hSecretKey);
DWORD dwMode = CRYPT_MODE_CBC;
CryptSetKeyParam(hSecretKey, KP_MODE, (LPBYTE)&dwMode, 0);
DWORD dwBlockLen = 0;
DWORD dwDataLen = sizeof(dwBlockLen);
CryptGetKeyParam(hSecretKey, KP_BLOCKLEN, (LPBYTE)&dwBlockLen, &dwDataLen, 0);
dwBlockLen /= 8;
LPBYTE pbTemp;
CryptGenRandom(hProvider, dwBlockLen, pbTemp);
CryptSetKeyParam(hKey, KP_IV, pbTemp, 0);
CryptEncrypt(hSecretKey, NULL, TRUE, 0, pData, &plainSize, dataSize);
我不确定EDE3部分 - 我在CryptoAPI文档中找不到任何关于它的参考;以上代码是否满足加密密钥的上述标题?