#include <string.h>
#include <errno.h>
#include <cstdio>
+#include <sstream>
+#include<iostream>
#include <memory>
using namespace WrtDB;
+extern "C"
+{
+ void InitWebAppInfo(const char* appId, const char* rootPath);
+}
+
namespace {
-const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 1008; // bytes
+const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 4096; // bytes
+const std::size_t ENCRYPTION_DEC_CHUNK_SIZE = 4; // bytes
+static bool initWebApp = false;
std::set<std::string>& getSupportedForEncryption()
{
int pBufSize)
{
using namespace Tizen::Base;
+ if(!initWebApp)
+ {
+ char* pAppId = null;
+ pAppId = (char*)calloc(appInfo->GetRemaining()+1, 1);
+ memcpy(pAppId, appInfo->GetPointer(), appInfo->GetRemaining());
+ InitWebAppInfo(pAppId, "");
+ free (pAppId);
+ initWebApp = true;
+ }
Tizen::Security::Crypto::_TrustZoneService* pInstance;
pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
ByteBuffer* getBuffer = pInstance->_TrustZoneService::EncryptN(*appInfo, pBuf);
return getBuffer;
}
+
+Tizen::Base::ByteBuffer* TEST_dec(
+ Tizen::Base::ByteBuffer* appInfo,
+ const unsigned char *plainBuffer,
+ int pBufSize)
+{
+ using namespace Tizen::Base;
+
+ Tizen::Security::Crypto::_TrustZoneService* pInstance;
+ pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
+
+ ByteBuffer pBuf;
+ pBuf.Construct(pBufSize);
+ const byte *pByte = reinterpret_cast<const byte*>(plainBuffer);
+ pBuf.SetArray(pByte, 0, pBufSize);
+ pBuf.Flip();
+
+ ByteBuffer* getBufferTEST =
+ pInstance->_TrustZoneService::DecryptN(*appInfo, pBuf);
+ return getBufferTEST;
+}
}
namespace Jobs {
{
bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get());
if (0 != bytesRead) {
-
ByteBuffer *getBuffer = EncryptChunkByTrustZone(
&appInfo,
inChunk.get(), bytesRead);
memcpy(outChunk.get(), getBuffer->GetPointer(), getBuffer->GetRemaining());
getBuffer->Reset();
+ char writeSize[ENCRYPTION_DEC_CHUNK_SIZE];
+ memset(writeSize, 0x00, ENCRYPTION_DEC_CHUNK_SIZE);
+ std::stringstream toString;
+ toString << decBufSize;
+ strncpy(writeSize, toString.str().c_str(), toString.str().length());
+
+ writeBytes((unsigned char*)writeSize,
+ ENCRYPTION_DEC_CHUNK_SIZE, outFile.Get());
writeBytes(outChunk.get(), decBufSize, outFile.Get());
}
} while (0 == std::feof(inFile.Get()));
- LogDebug("File encrypted successfully");
-
outFile.Reset();
inFile.Reset();
+ LogDebug("File encrypted successfully");
LogDebug("Remove plain-text file: " << fileName);
if (0 != unlink(fileName.c_str()))
{