/*
* DataProtectUnprotect.cpp
* Copyright (c) 2011 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);
//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;
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);
}
}
|