Digitally Sign A Text File


  • I need to be able to take a simple text file and append a digital signature to it.  I have a Digital ID from VeriSign installed on my machine.  I am able to use the following code to get the certificate:

    store = new X509Store(StoreName.My, StoreLocation.CurrentUser);


    X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindByIssuerName,"veriSign",true);



    cert = col[0];


    catch (System.Exception e)


    throw new Exception("VeriSign digital signature not found.");


    All I need to do is use this cert to sign the file.  The contents of file does not need to be encrypted.   Does any one have an example I can look at or some insight on how I might be able to do this. 

    Thanks in advance.

    Thursday, December 07, 2006 4:51 PM

All replies

  • Someone answer this man's post please...


    I'm having the same issue. I'm starting to believe that you can't actually sign files  (without encrypting them and sending them as messages).


    What I've tried doing is creating a SignedCMS object -- you can search for it at the MSDN library. But, though you can compute a signature, there seems to be no way to get the file and the signature data without calling the Encrypt() function of SignedCMS.


    I've been trying to use .NET as an alternative to CAPICOM, since Microsoft says CAPICOM is not supported in Vista...


    But, if you're not developing for Vista, CAPICOM is a fully functional alternative to .NET.

    Wednesday, June 27, 2007 8:37 PM
  • You may want to read (At the bottom there is a paragraph about signing and encrypting data with code snippets,figure 11 and 12, that do what you're looking for)
    Wednesday, June 27, 2007 9:32 PM
  • A) The only way to digitally sign a text file and still have a text file would be to store the signature as a separate file.  The signature itself will be binary data, and if added to your text file, this will make the file (at least partly) binary.


    B) The linked example shows only how to use the .NET Framework to perform the actions provided by the SignedData class of CAPICOM.  Where are examples showing how to replace the SignedCode class?  The distinction is critical:  The SignedCode class allows signature application and verification purely by extending the original data file.  SignedCode could even be used to sign a plain text file, so long as the file included a terminator and your text reader respected the terminator character.  The 'signature' portion would occur in the file after the terminator - thus giving you a signed file that is simultaneously an plain text file.  CAPICOM's SignedCode class can do this - how do you do it using the .NET Framework?

    Monday, July 30, 2007 7:13 PM