I write a program to encrypt/decrypt file with CryptoAPI certificate
store , like "EncryptTo/DecryptTo: Encryption in .NET with CryptoAPI
Certificate Stores" do, but not use p/invoke.
EncryptTo:
Find the certificate(.cer) i need by subject name str and get the
certificate context, then import the public key to default crypt provider by
CryptImportPublicKeyInfo(PCCERT_CONTEXT->CERT_PUBLIC_KEY_INFO).
Generate a random session key and export encrypted session key to
encrypted file by CryptExportKey(hSessionKey, hPublicKey, SIMPLEBLOB, 0,
pbKeyBlob, &dwKeyBlobLen).
encrypt file using session key.
DecryptTo:
Find the certificate(.pxf) i need by subject name str and get the
certificate context, then get CRYPT_KEY_PROV_INFO by
CertGetCertificateContextProperty(CERT_KEY_PROV_INFO_PROP_ID) and use
CRYPT_KEY_PROV_INFO->pwszContainerName to get crypt provider.
Get session key blob from encrypt file and import session key to
provider(get about)by CryptImportKey.
Decrypt file.
When i use the program to encrypt file in a computer(Win2000) by
certificate(.cer) and decrypt the file in another computer(WinXP) by
certificate (.pxf), the program work correctly. Contra, encrypt file in
WinXP and decrypt in Win2000, have a NTE_BAD_FLAGS error at CryptImportKey
and I only set the dwFlag=0.
It puzzle me several days, and help is appreciated.
Regards
Zheng
Regards
Miro
"Lokicer" <lok...@163.com> wrote in message
news:OoqXvB3g...@TK2MSFTNGP11.phx.gbl...
Regards Miro
"Lokicer" <lok...@163.com> wrote in message
news:OoqXvB3g...@TK2MSFTNGP11.phx.gbl...