Link to home
Start Free TrialLog in
Avatar of davinder101
davinder101

asked on

Problem with CRYPTOAPI

Hi, i am using cryptoapi to encrypt my files. The files are decrypted if i decrypt them on the same system with same user, but if i try to decrypt them with different user or on different system, decryption fails. The function i am using to encrypt files are:-
        CryptAcquireContext();
      CryptGetUserKey(  );
        CryptGetUserKey(  );
       GeneratePrivateKey();
       CryptGenKey();
etc.
The fuction failing on decryption is
      CryptImportKey();
Can anybody tell how to decrypt files on a different system;
Thanks;
Avatar of mahesh1402
mahesh1402
Flag of India image

The fuction failing on decryption is CryptImportKey();

what GetLastError returns ?

-MAHESH
Avatar of davinder101
davinder101

ASKER

The value return by GetLastError() is 2148073477.
Thanks
and what CryptImportKey() returns out of following ?

ERROR_INVALID_HANDLE
ERROR_INVALID_PARAMETER
NTE_BAD_ALGID
NTE_BAD_DATA
NTE_BAD_FLAGS
NTE_BAD_TYPE
NTE_BAD_UID
NTE_BAD_VER

look into return error code and try to change accordingly.

-MAHESH
The value is NTE_BAD_DATA. But why it is decrypting on the same machine.
I think it has something to do with the public key used to form the public-private key pair.
Thanks.
Hi, from microsoft news group, i came to know that during encryption one has to encypt the file by using the private key of the source system and the public key of the destination system. Then only we can decrypt the file on the destination system. Can any one tell me how to get the key from the destiantion system.
Thanks,
Is this you are looking for ?
http://support.microsoft.com/kb/228786
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial