Xceed Encryption Library Documentation
Examples / Digitally signing a file (C# example)
In This Topic
    Digitally signing a file (C# example)
    In This Topic
    C# Copy Code

    // Digital signature creation example for C# (single pass)            

    XceedEncryptionLib.XceedSigning signer = new XceedEncryptionLib.XceedSigningClass();

    signer.License( @"your license key" );      

    try
    {
      XceedEncryptionLib.XceedRSASigningMethod rsa = new XceedEncryptionLib.XceedRSASigningMethodClass(); 

      // The following call to SetRandomKeyPair would, in the real world,
      // be replaced by the assignment of a Private Key to the PrivateKey property.

      object seed = null;
      rsa.SetRandomKeyPair( 512, ref seed ); 

      // Set the signing method type
      signer.SigningMethod = rsa; 

      // Read the file and create the digital signature
      signer.ReadFile( @"c:\test\file.txt", 0, 0, XceedEncryptionLib.EXEFileProcessing.efpSign, true ); 

      // Fetch the digital signature
      object signature = rsa.get_Signature(); 

      // Verify the signature
      signer.ReadFile( @"c:\test\file.txt", 0, 0,
                       XceedEncryptionLib.EXEFileProcessing.efpVerify, true );        
    }
    catch( System.Runtime.InteropServices.COMException except )
    {
      MessageBox.Show( except.ToString() );
    }