Xceed Encryption Library Documentation
Examples / Signing and verifying data entirely in memory (VC++ example)
In This Topic
    Signing and verifying data entirely in memory (VC++ example)
    In This Topic
    VC++ Copy Code

    // Signing / Verifying example 

    // 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 );   

      const char* pszSource = "This is the data to sign"; 
      DWORD dwSourceSize = lstrlen( pszSource ) + 1; // Let's say we want to sign the null-char too 
      BYTE* pcSignature = NULL; 
      short nSignatureSize = 0;  

      piSign->Sign( ( BYTE* )pszSource, dwSourceSize, TRUE );  

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

      //Do something with the Signature...  

      MessageBox( NULL, "Data signed successfully", "Signing result", MB_OK );  

      long lVerified = FALSE; 

      piSign->Verify( ( BYTE* )pszSource, dwSourceSize, TRUE, &lVerified );  

      if( lVerified ) 
      { 
        MessageBox( NULL, "Data verified successfully", "Verification result", MB_OK ); 
      } 
      else 
      { 
        // Should not happen 
        MessageBox( NULL, "Signature verification failed", "Verification result", MB_OK ); 
      }  

      CoTaskMemFree( pcSignature ); 
    }
    catch( const _com_error& xErr )
    {
      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();