SOL9 2.0 Sample: DataProtectUnprotect

SOL9 2.0 Samples

1 Screenshot







2 Source code

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


// SOL9
// 2009/04/16

#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;
        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);
                _tprintf(_T("Description  : %s\n"), pDescription);
            }
        }


        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;
        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);
                _tprintf(_T("Description  : %s\n"), pDescription);

            }
        }


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

}

Last modified: 11 Nov 2009

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