title: How can I get certificate public key from SQL Server?
body: <p>I have imported certificate into a SQL Server database.</p>
  
  <pre><code> create certificate MyCertificate from file = 'c:\certificate.cer';
  </code></pre>
  
  <p>Now I want to retrieve public key of that certificate. How to do it ?</p>
  
  <p>I can do</p>
  
  <pre><code>select * from sys.certificates
  </code></pre>
  
  <p>but there is no public key column.</p>
  
  <p>I know I can save it to disk by</p>
  
  <pre><code>backup certificate MyCertificate to file = 'c:\MyCertificate.cer';
  </code></pre>
  
  <p>but that's not what I want. I just need database to tell me public key or somehow get me whole certificate but I dont want to use files.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I wanted to verify digital signature of a row in database table using SQL Server and certificate. But since function <strong>VerifySignedByCert</strong> doesn't check certificate expiration date (according to this note: <em>Built-in functions for encryption and signing do not check the expiration dates of certificates. Users of these functions must decide when to check certificate expiration.</em> in <a href="http://msdn.microsoft.com/en-US/library/ms187798%28v=SQL.90%29.aspx" rel="noreferrer">http://msdn.microsoft.com/en-US/library/ms187798%28v=SQL.90%29.aspx</a>) I have to do it manually in C# code. </p>
  
  <p>That's why I wanted to get certificate public key and expiration date (which can be found in sys.certificates). But it seems that storing certificate in a varbinary column in a table is the best option. Or are there other better ways how to achieve this ?</p>
  
  <p>Thank you for your help</p>