update to new compound in crypt

This commit is contained in:
Elena.Subbotina
2022-10-28 13:09:13 +03:00
parent a8d819694d
commit addabe9fca
10 changed files with 662 additions and 400 deletions

View File

@ -22,11 +22,16 @@
int _tmain(int argc, _TCHAR* argv[])
{
std::wstring password = L"password";
#define __CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
std::wstring password = L"123";
ECMACryptFile crypt_file;
bool result = false, bDataIntegrity = false;
std::wstring srcFileName = L"D:\\test\\_bad_86\\crypt_file_test.docx";
std::wstring srcFileName = L"D:\\tests\\__53\\test123-1.rtf-my.docx";
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
std::wstring dstFileName2 = dstFileName + L".oox";
@ -40,17 +45,19 @@ int _tmain(int argc, _TCHAR* argv[])
//std::wstring dstFileName1 = srcFileName1 + L".oox";
//result = crypt_file.DecryptOfficeFile(srcFileName1, dstFileName1, password, bDataIntegrity);
//result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
//result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
std::wstring addit_name = L"11111111111111111111111111111";
std::string addit_info = crypt_file.ReadAdditional(srcFileName, addit_name);
//std::wstring addit_name = L"11111111111111111111111111111";
//
//std::string addit_info = crypt_file.ReadAdditional(srcFileName, addit_name);
std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
//std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
//
//addit_info += std::string(temp.begin(), temp.end());
//crypt_file.WriteAdditional(srcFileName, addit_name, addit_info);
addit_info += std::string(temp.begin(), temp.end());
crypt_file.WriteAdditional(srcFileName, addit_name, addit_info);
_CrtDumpMemoryLeaks();
return 0;
}

View File

@ -3,12 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OfficeFileCrypt", "..\win32\ECMACryptReader.vcxproj", "{C27E9A9F-3A17-4482-9C5F-BF15C01E747C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cryptlib", "..\..\Common\3dParty\cryptopp\cryptlib.vcxproj", "{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CompoundFileLib", "..\..\Common\cfcpp\CompoundFileLib.vcxproj", "{FA22BAB4-E93E-459D-8A5F-16764FBBED40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -21,18 +23,6 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Debug|Win32.ActiveCfg = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Debug|Win32.Build.0 = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Debug|x64.ActiveCfg = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Debug|Win32.ActiveCfg = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Debug|Win32.Build.0 = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Debug|x64.ActiveCfg = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Release|Win32.ActiveCfg = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Release|Win32.Build.0 = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Release|x64.ActiveCfg = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Release|Win32.ActiveCfg = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Release|Win32.Build.0 = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Release|x64.ActiveCfg = Release|Win32
{C27E9A9F-3A17-4482-9C5F-BF15C01E747C}.Debug|Win32.ActiveCfg = Debug|Win32
{C27E9A9F-3A17-4482-9C5F-BF15C01E747C}.Debug|Win32.Build.0 = Debug|Win32
{C27E9A9F-3A17-4482-9C5F-BF15C01E747C}.Debug|x64.ActiveCfg = Debug|x64
@ -65,6 +55,36 @@ Global
{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}.Release|Win32.Build.0 = Release|Win32
{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}.Release|x64.ActiveCfg = Release|x64
{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}.Release|x64.Build.0 = Release|x64
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Debug|Win32.ActiveCfg = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Debug|Win32.Build.0 = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Debug|x64.ActiveCfg = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Debug|Win32.ActiveCfg = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Debug|Win32.Build.0 = Debug|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Debug|x64.ActiveCfg = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Debug|x64.Build.0 = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Release|Win32.ActiveCfg = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Release|Win32.Build.0 = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Release|x64.ActiveCfg = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.DLL-Import Release|x64.Build.0 = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Release|Win32.ActiveCfg = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Release|Win32.Build.0 = Release|Win32
{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}.Release|x64.ActiveCfg = Release|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Debug|Win32.ActiveCfg = Debug|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Debug|Win32.Build.0 = Debug|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Debug|x64.ActiveCfg = Debug|x64
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Debug|x64.Build.0 = Debug|x64
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Debug|Win32.ActiveCfg = Debug|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Debug|Win32.Build.0 = Debug|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Debug|x64.ActiveCfg = Debug|x64
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Debug|x64.Build.0 = Debug|x64
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Release|Win32.ActiveCfg = Release|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Release|Win32.Build.0 = Release|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Release|x64.ActiveCfg = Release|x64
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.DLL-Import Release|x64.Build.0 = Release|x64
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Release|Win32.ActiveCfg = Release|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Release|Win32.Build.0 = Release|Win32
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Release|x64.ActiveCfg = Release|x64
{FA22BAB4-E93E-459D-8A5F-16764FBBED40}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,200 +0,0 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="Test"
ProjectGUID="{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}"
RootNamespace="Test"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../DesktopEditor/xml/build/vs2005;../../DesktopEditor/xml/libxml2/include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Common"
>
<File
RelativePath="..\..\Common\OfficeFileFormatChecker.h"
>
</File>
<File
RelativePath="..\..\Common\OfficeFileFormatChecker2.cpp"
>
</File>
<File
RelativePath="..\..\Common\3dParty\pole\pole.cpp"
>
</File>
<File
RelativePath="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp"
>
</File>
</Filter>
<File
RelativePath=".\Test.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}</ProjectGuid>
<RootNamespace>Test</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>14.0.25431.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../../DesktopEditor/xml/build/vs2005;../../DesktopEditor/xml/libxml2/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\Common\3dParty\pole\pole.cpp" />
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp" />
<ClCompile Include="..\..\Common\OfficeFileFormatChecker2.cpp" />
<ClCompile Include="Test.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\3dParty\cryptopp\cryptlib.vcxproj">
<Project>{3423ec9a-52e4-4a4d-9753-edebc38785ef}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Common\cfcpp\CompoundFileLib.vcxproj">
<Project>{fa22bab4-e93e-459d-8a5f-16764fbbed40}</Project>
</ProjectReference>
<ProjectReference Include="..\win32\ECMACryptReader.vcxproj">
<Project>{c27e9a9f-3a17-4482-9c5f-bf15c01e747c}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Common">
<UniqueIdentifier>{2f29e4fd-6ebd-4ba1-8dc7-6b542a5dfd5d}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Common\OfficeFileFormatChecker.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\Common\OfficeFileFormatChecker2.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\..\Common\3dParty\pole\pole.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Test.cpp" />
</ItemGroup>
</Project>

View File

@ -776,41 +776,46 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s
{
return false;
}
cryptor.UpdateDataIntegrity(data_out, lengthData);
cryptor.UpdateDataIntegrity(data_out, lengthData);
bool bLargeFile = (lengthData > 3 * 1024 * 1024);
bLargeFile = true; // test ???
//-------------------------------------------------------------------
#if (defined(_WIN32) || defined(_WIN64)) && defined(USE_MSSTORAGE)
IStorage *winStorage = NULL;
StgCreateDocfile(file_name_out.c_str(), STGM_CREATE|STGM_SHARE_EXCLUSIVE|STGM_READWRITE, 0, &winStorage);
IStream *winStream = NULL;
#else
//-------------------------------------------------------------------
POLE::Storage *pStorage = new POLE::Storage(file_name_out.c_str());
if (!pStorage)return false;
POLE::Storage *pStorage = NULL;
CFCPP::CompoundFile *pStorageNew = NULL;
if (!pStorage->open(true, true))
if (bLargeFile)
{
delete pStorage;
return false;
pStorageNew = new CFCPP::CompoundFile(CFCPP::Ver_3, CFCPP::Default);
}
POLE::Stream *pStream = NULL;
#endif
//-------------------------------------------------------------------
#if (defined(_WIN32) || defined(_WIN64)) && defined(USE_MSSTORAGE)
ULONG nWritten;
winStorage->CreateStream(L"EncryptedPackage", STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &winStream);
winStream->Write(data_out, lengthData, &nWritten);
winStream->Release();
#else
pStream = new POLE::Stream(pStorage, L"EncryptedPackage", true, lengthData);
pStream->write(data_out, lengthData);
else
{
pStorage = new POLE::Storage(file_name_out.c_str());
if (!pStorage)return false;
pStream->flush();
delete pStream;
#endif
if (!pStorage->open(true, true))
{
delete pStorage;
return false;
}
}
//-------------------------------------------------------------------
if (bLargeFile)
{
std::shared_ptr<CFCPP::CFStream> oPackage = pStorageNew->RootStorage()->AddStream(L"EncryptedPackage");
oPackage->Write((char*)data_out, 0, lengthData);
}
else
{
POLE::Stream *pStream = new POLE::Stream(pStorage, L"EncryptedPackage", true, lengthData);
pStream->write(data_out, lengthData);
pStream->flush();
delete pStream;
}
//-------------------------------------------------------------------
if (data_out)
@ -821,124 +826,133 @@ bool ECMACryptFile::EncryptOfficeFile(const std::wstring &file_name_inp, const s
cryptor.GetCryptData(cryptData);
#if (defined(_WIN32) || defined(_WIN64)) && defined(USE_MSSTORAGE)
winStorage->CreateStream(L"EncryptionInfo", STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &winStream);
if (cryptData.bAgile)
if (bLargeFile)
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0004; //agile
winStream->Write((unsigned char*)&VersionInfoMajor, 2, &nWritten);
winStream->Write((unsigned char*)&VersionInfoMinor, 2, &nWritten);
_UINT32 nEncryptionInfoFlags = 64;
winStream->Write((unsigned char*)&nEncryptionInfoFlags, 4, &nWritten);
std::string strXml;
WriteXmlEncryptionInfo(cryptData, strXml);
winStream->Write((unsigned char*)strXml.c_str(), strXml.length(), &nWritten);
std::shared_ptr<CFCPP::CFStream> oInfo = pStorageNew->RootStorage()->AddStream(L"EncryptionInfo");
if (cryptData.bAgile)
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0004; //agile
std::streamsize position = 0;
oInfo->Write((char*)&VersionInfoMajor, position, 2); position += 2;
oInfo->Write((char*)&VersionInfoMinor, position, 2); position += 2;
_UINT32 nEncryptionInfoFlags = 64;
oInfo->Write((char*)&nEncryptionInfoFlags, position, 4); position += 4;
std::string strXml;
WriteXmlEncryptionInfo(cryptData, strXml);
oInfo->Write(strXml.c_str(), position, strXml.length()); position += strXml.length();
}
else
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0002; // standart
std::streamsize position = 0;
oInfo->Write((char*)&VersionInfoMajor, position, 2); position += 2;
oInfo->Write((char*)&VersionInfoMinor, position, 2); position += 2;
_UINT32 nEncryptionInfoFlags = 0;
bool fCryptoAPI = true, fDocProps = false, fExternal = false, fAES = cryptData.cipherAlgorithm != CRYPT_METHOD::RC4;
SETBIT(nEncryptionInfoFlags, 2, fCryptoAPI);
SETBIT(nEncryptionInfoFlags, 3, fDocProps);
SETBIT(nEncryptionInfoFlags, 4, fExternal);
SETBIT(nEncryptionInfoFlags, 5, fAES);
oInfo->Write((char*)&nEncryptionInfoFlags, position, 4); position += 4;
int nEncryptionInfoSize = 4096;
unsigned char* byteEncryptionInfo = new unsigned char[nEncryptionInfoSize];
WriteStandartEncryptionInfo(byteEncryptionInfo, nEncryptionInfoSize, cryptData);
oInfo->Write((char*)byteEncryptionInfo, position, 4); position += nEncryptionInfoSize;
delete[]byteEncryptionInfo;
}
}
else
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0002; // standart
winStream->Write((unsigned char*)&VersionInfoMajor, 2, &nWritten);
winStream->Write((unsigned char*)&VersionInfoMinor, 2, &nWritten);
POLE::Stream *pStream = new POLE::Stream(pStorage, L"EncryptionInfo", true);
_UINT32 nEncryptionInfoFlags = 0;
bool fCryptoAPI = true, fDocProps = false, fExternal = false, fAES = cryptData.cipherAlgorithm != CRYPT_METHOD::RC4;
if (cryptData.bAgile)
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0004; //agile
SETBIT(nEncryptionInfoFlags, 2, fCryptoAPI);
SETBIT(nEncryptionInfoFlags, 3, fDocProps);
SETBIT(nEncryptionInfoFlags, 4, fExternal);
SETBIT(nEncryptionInfoFlags, 5, fAES);
winStream->Write((unsigned char*)&nEncryptionInfoFlags, 4, &nWritten);
pStream->write((unsigned char*)&VersionInfoMajor, 2);
pStream->write((unsigned char*)&VersionInfoMinor, 2);
int nEncryptionInfoSize = 4096;
unsigned char* byteEncryptionInfo = new unsigned char[nEncryptionInfoSize];
_UINT32 nEncryptionInfoFlags = 64;
pStream->write((unsigned char*)&nEncryptionInfoFlags, 4);
WriteStandartEncryptionInfo(byteEncryptionInfo, nEncryptionInfoSize, cryptData);
std::string strXml;
WriteXmlEncryptionInfo(cryptData, strXml);
winStream->Write(byteEncryptionInfo, nEncryptionInfoSize, &nWritten);
delete []byteEncryptionInfo;
pStream->write((unsigned char*)strXml.c_str(), strXml.length());
}
else
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0002; // standart
pStream->write((unsigned char*)&VersionInfoMajor, 2);
pStream->write((unsigned char*)&VersionInfoMinor, 2);
_UINT32 nEncryptionInfoFlags = 0;
bool fCryptoAPI = true, fDocProps = false, fExternal = false, fAES = cryptData.cipherAlgorithm != CRYPT_METHOD::RC4;
SETBIT(nEncryptionInfoFlags, 2, fCryptoAPI);
SETBIT(nEncryptionInfoFlags, 3, fDocProps);
SETBIT(nEncryptionInfoFlags, 4, fExternal);
SETBIT(nEncryptionInfoFlags, 5, fAES);
pStream->write((unsigned char*)&nEncryptionInfoFlags, 4);
int nEncryptionInfoSize = 4096;
unsigned char* byteEncryptionInfo = new unsigned char[nEncryptionInfoSize];
WriteStandartEncryptionInfo(byteEncryptionInfo, nEncryptionInfoSize, cryptData);
pStream->write(byteEncryptionInfo, nEncryptionInfoSize);
delete[]byteEncryptionInfo;
}
pStream->flush();
delete pStream;
}
winStream->Release();
#else
pStream = new POLE::Stream(pStorage, L"EncryptionInfo", true);
if (cryptData.bAgile)
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0004; //agile
pStream->write((unsigned char*)&VersionInfoMajor, 2);
pStream->write((unsigned char*)&VersionInfoMinor, 2);
_UINT32 nEncryptionInfoFlags = 64;
pStream->write((unsigned char*)&nEncryptionInfoFlags, 4);
std::string strXml;
WriteXmlEncryptionInfo(cryptData, strXml);
pStream->write((unsigned char*)strXml.c_str(), strXml.length());
}
else
{
_UINT16 VersionInfoMajor = 0x0004, VersionInfoMinor = 0x0002; // standart
pStream->write((unsigned char*)&VersionInfoMajor, 2);
pStream->write((unsigned char*)&VersionInfoMinor, 2);
_UINT32 nEncryptionInfoFlags = 0;
bool fCryptoAPI = true, fDocProps = false, fExternal = false, fAES = cryptData.cipherAlgorithm != CRYPT_METHOD::RC4;
SETBIT(nEncryptionInfoFlags, 2, fCryptoAPI);
SETBIT(nEncryptionInfoFlags, 3, fDocProps);
SETBIT(nEncryptionInfoFlags, 4, fExternal);
SETBIT(nEncryptionInfoFlags, 5, fAES);
pStream->write((unsigned char*)&nEncryptionInfoFlags, 4);
int nEncryptionInfoSize = 4096;
unsigned char* byteEncryptionInfo = new unsigned char[nEncryptionInfoSize];
WriteStandartEncryptionInfo(byteEncryptionInfo, nEncryptionInfoSize, cryptData);
pStream->write(byteEncryptionInfo, nEncryptionInfoSize);
delete []byteEncryptionInfo;
}
pStream->flush();
delete pStream;
#endif
//-------------------------------------------------------------------
if (false == documentID.empty())
{
std::string utfDocumentID = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(documentID);
#if (defined(_WIN32) || defined(_WIN64)) && defined(USE_MSSTORAGE)
winStorage->CreateStream(L"DocumentID", STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &winStream);
winStream->Write((BYTE*)utfDocumentID.c_str(), utfDocumentID.length(), &nWritten);
winStream->Release();
#else
pStream = new POLE::Stream(pStorage, L"DocumentID", true, utfDocumentID.length());
pStream->write((BYTE*)utfDocumentID.c_str(), utfDocumentID.length());
if (bLargeFile)
{
pStream->flush();
delete pStream;
#endif
std::shared_ptr<CFCPP::CFStream> oDocumentID = pStorageNew->RootStorage()->AddStream(L"DocumentID");
oDocumentID->Write(utfDocumentID.c_str(), 0, utfDocumentID.length());
}
else
{
POLE::Stream *pStream = new POLE::Stream(pStorage, L"DocumentID", true, utfDocumentID.length());
pStream->write((BYTE*)utfDocumentID.c_str(), utfDocumentID.length());
pStream->flush();
delete pStream;
}
}
//-------------------------------------------------------------------
#if (defined(_WIN32) || defined(_WIN64)) && defined(USE_MSSTORAGE)
if (winStorage)
winStorage->Release();
#else
pStorage->close();
delete pStorage;
#endif
if (bLargeFile)
{
pStorageNew->Save(file_name_out);
pStorageNew->Close();
delete pStorageNew;
}
else
{
pStorage->close();
delete pStorage;
}
//
////test back---------------------------------------------------------------------------------test back
// ECMADecryptor decryptor;