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

    // This code uses the #import directive.
    // Put the following line at the beginning of your module 

    #import "XCEEDCRY.DLL" no_namespace named_guids 

    CoInitialize( NULL ); 

    try
    {
      IXceedSigningPtr piSign; 

      piSign.CreateInstance( CLSID_XceedSigning ); 
      piSign->License( _bstr_t( L"your license key ) ); 

      IXceedRSASigningMethodPtr piRSA; 
      piRSA.CreateInstance( CLSID_XceedRSASigningMethod );  

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

      piRSA->SetRandomKeyPair( 512, NULL, 0 ); 

      piSign->SigningMethod = IXceedSignDataPtr( piRSA );  

      BYTE* pcSignature = NULL; 
      short nSignatureSize; 
      DWORD dwBytesRead;  

      piSign->ReadFile( "c:\\temp\\source.txt", 0, 0, efpSign, TRUE, &dwBytesRead );  

      piRSA->GetSignature( &pcSignature, &nSignatureSize );  

      //Do something with the Signature... 

      CoTaskMemFree( pcSignature );  

      MessageBox( NULL, "File signed successfully to memory", "Signing result", MB_OK );  

      piSign->ReadFile( "c:\\temp\\source.txt", 0, 0, efpVerify, TRUE, &dwBytesRead ); 

      MessageBox( NULL, "Data verified successfully", "Verifying result", MB_OK ); 
    }
    catch( const _com_error& xErr )
    {
      if( xErr.Error() == eerVerifyFailed ) 
      { 
        MessageBox( NULL, "Signature verification failed" , "Verifying result", MB_OK ); 
      } 
      else 
      { 
        char szMsg[50]; 
        wsprintf( szMsg, "Error %08x\n", xErr.Error() ); 
        MessageBox( NULL, szMsg, "Error", MB_OK ); 
      } 
    }
    catch( ... )
    {
      MessageBox( NULL, "Unknown error", "Error", MB_OK ); 

    CoUninitialize();