title: WinAPI -> CryptoAPI -> RSA, encrypt with private, decrypt with public
body: <p>Good day.</p>
  
  <p>I need to teach Windows CryptoAPI to encrypt the message with private (not public) part of the key, and decrypt with public. This is necessary to give users information, that they can read, but can't change.</p>
  
  <p><strong>How it works now:</strong></p>
  
  <p>I get the context</p>
  
  <pre><code>CryptAcquireContext(@Prov, PAnsiChar(containerName), nil, PROV_RSA_FULL, 0)
  </code></pre>
  
  <p>generate a key pair</p>
  
  <pre><code>CryptGenKey(Prov, CALG_RSA_KEYX, CRYPT_EXPORTABLE, @key)
  </code></pre>
  
  <p>Encrypt (and the problem is here. "key" - a keypair, and the function uses its public part);</p>
  
  <pre><code>CryptEncrypt(key, 0, true, 0, @res[1], @strLen, buffSize)
  </code></pre>
  
  <p>Decrypt (the same problem here, it uses the private part of the key)</p>
  
  <pre><code>CryptDecrypt(key, 0, true, 0, @res[1], @buffSize)
  </code></pre>
  
  <p>Thank you for your attention / help.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Yes, I could use a digital signature and other metods... </p>
  
  <p>The problem is that I need to encrypt one database field and make sure that no one but me can change it. It will be possible to read this field only with the help of my program (till someone decompiles it and get public key). This could be done with symmetrical key and digital signatures, but then i will need to create another field and store another key and so on... </p>
  
  <p>I do hope that we can somehow teach WIN API to do as I want. I know that i can do so with RSA, and I hope that somehow WinAPI supports this feature.</p>