Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Encounter NTE_BAD_FLAGS Error When import SIMPLEBLOB session key

201 views
Skip to first unread message

Lokicer

unread,
Aug 16, 2004, 5:07:05 AM8/16/04
to
Hi all,

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

Miro Masnoglav

unread,
Aug 17, 2004, 1:55:31 AM8/17/04
to
Just an idea:
Be sure that you are using the same Crypto providers and algorithms on both
OS.

Regards
Miro

"Lokicer" <lok...@163.com> wrote in message
news:OoqXvB3g...@TK2MSFTNGP11.phx.gbl...

Miro Masnoglav

unread,
Aug 17, 2004, 2:13:56 AM8/17/04
to
See also discussion on Microsoft.public.platformsdk.security newsgroup
with subject
"CryptEncrypt & CryptDecrypt Win2000 & Win XP issue.."

Regards Miro

"Lokicer" <lok...@163.com> wrote in message
news:OoqXvB3g...@TK2MSFTNGP11.phx.gbl...

0 new messages