SOL9 Sample: DataProtectUnprotect

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * DataProtectUnprotect.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/04/16
// 2015/12/21 Updated.

#include <sol/crypt/DataProtector.h>
#include <sol/crypt/DataUnprotector.h>
#include <sol/String.h>
#include <sol/Locale.h>

void _tmain(int argc, TCHAR** argv)
{
  Locale locale;

  {
    _tprintf(_T("1 DataProtector and DataUnprotector with UI\n"));

    DATA_BLOB inputData;
    DATA_BLOB protectedData;
    DATA_BLOB verifiedData;
    memset(&inputData, 0, sizeof(inputData));
    memset(&protectedData, 0, sizeof(protectedData));
    memset(&verifiedData, 0, sizeof(verifiedData));
    
    BYTE *pbinputData =(BYTE *)"SOL9 Data protection sample with UI.";
    DWORD cbinputData = strlen((char *)pbinputData)+1;
    inputData.pbData = pbinputData;    
    inputData.cbData = cbinputData;
    const wchar_t* desc = L"Protection with UI";
    wchar_t* pDescription = NULL;
   
    DataProtector protector;
    if (protector.protect(inputData, protectedData, desc, true) == NO_ERROR) {

      DataUnprotector unprotector;
      if (unprotector.unprotect(protectedData, verifiedData, &pDescription, true) == NO_ERROR) {
        String pdata = (char*)verifiedData.pbData;
        _tprintf(_T("The decrypted: %s\n"), (const TCHAR*)pdata);
        //2011/09/05 Modified the following lines.
        String desc = pDescription;
        _tprintf(_T("Description  : %s\n"), (const TCHAR*)desc);
      }
    }

    LocalFree(pDescription);
    LocalFree(protectedData.pbData);
    LocalFree(verifiedData.pbData);
  }


  {
    _tprintf(_T("2 DataProtector and DataUnprotector without UI\n"));

    DATA_BLOB inputData;
    DATA_BLOB protectedData;
    DATA_BLOB verifiedData;
    memset(&inputData, 0, sizeof(inputData));
    memset(&protectedData, 0, sizeof(protectedData));
    memset(&verifiedData, 0, sizeof(verifiedData));
    

    BYTE *pbinputData =(BYTE *)"SOL9 Data protection sample without UI.";
    DWORD cbinputData = strlen((char *)pbinputData)+1;
    inputData.pbData = pbinputData;    
    inputData.cbData = cbinputData;
    const wchar_t* desc = L"Protection without UI";
    wchar_t* pDescription = NULL;
   
    DataProtector protector;
    if (protector.protect(inputData, protectedData, desc, false) == NO_ERROR) {

      DataUnprotector unprotector;
      if (unprotector.unprotect(protectedData, verifiedData, &pDescription, false) == NO_ERROR) {
        String pdata = (char*)verifiedData.pbData;
        _tprintf(_T("The decrypted: %s\n"), (const TCHAR*)pdata);
        //2011/09/05 Modified the following lines.
        String desc = pDescription;
        _tprintf(_T("Description  : %s\n"), (const TCHAR*)desc);
      }
    }

    LocalFree(pDescription);
    LocalFree(protectedData.pbData);
    LocalFree(verifiedData.pbData);
  }

}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.