Hi1. Actually i am taking a file c:\myfile.txt in which plain text is written. I want to encrypt the content of this file using a public key of the logged in user(e.g. administrator) and the encrypted file content is to be written to c:\encrypt.txt file.
2. Finally i will read content of c:\encrypt.txt file and decrypt it using private key of the logged in user whose certificate is installed in the system along with private key.
3. I have created two functions encryptFile() and decryptFile() for the above said operations. In the encryptFile function
the cryptoAPI CryptAcquireContext function is used to acquire a handle to a particular
[DllImport ("advapi32.dll", CallingConvention=CallingConvention.StdCall, SetLastError=
public
// dwFlags definitions for CryptAcquireContext
// CryptSetProvParam
IntPtr hCryptProv = IntPtr.Zero;
ulong
IntPtr hKey = IntPtr.Zero;
byte
uint
When i am using the code written below then i acquire a handle to a particular key conatiner within a particular (CSP).
if
null
EncryptDecrypt.Form1.CRYPT_VERIFYCONTEXT))
{
Console.Out.WriteLine("\n CSP has been acquired");
}
But when i use
EncryptDecrypt.Form1.CRYPT_MACHINE_KEYSET))
THIS CODE DID NOT GET THE HANDLE TO THE CONTAINER
After the above code this code follows:
if (EncryptDecrypt.Form1.CryptGetUserKey(hCryptProv,
EncryptDecrypt.Form1.AT_KEYEXCHANGE,
ref hXchgKey))
Console.Out.WriteLine("\n User public key has be retrived");
And we did not get the key