This commit is contained in:
ElenaSubbotina
2018-12-05 15:43:01 +03:00
parent 14f4364962
commit 8bc8b7cf58
7 changed files with 82 additions and 26 deletions

View File

@ -44,6 +44,7 @@
#include "../formulasconvert/formulasconvert.h"
#include "../../../OfficeCryptReader/source/CryptTransform.h"
namespace cpdoccore {
namespace oox {
@ -174,6 +175,14 @@ void xlsx_table_state::set_protection(bool val, const std::wstring &key, const s
{
protect_key_algorithm = algorithm.substr(pos + 1);
}
//test
//CRYPT::odfWriteProtect protect;
//protect.SetProtectKey(DecodeBase64(protect_key));
//protect.SetPassword(L"123");
//bool res = protect.Verify();
}
unsigned int xlsx_table_state::columns_count() const

View File

@ -332,22 +332,6 @@ bool odf_document::Impl::decrypt_folder (const std::wstring &password, const std
}
return result;
}
std::string DecodeBase64(const std::wstring & value1)
{
int nLength = 0;
unsigned char *pData = NULL;
std::string result;
std::string value(value1.begin(), value1.end());
NSFile::CBase64Converter::Decode(value.c_str(), value.length(), pData, nLength);
if (pData)
{
result = std::string((char*)pData, nLength);
delete []pData; pData = NULL;
}
return result;
}
bool odf_document::Impl::decrypt_file (const std::wstring &password, const std::wstring & srcPath, const std::wstring & dstPath, office_element_ptr element, int file_size )
{
manifest_encryption_data* encryption_data = dynamic_cast<manifest_encryption_data*>(element.get());

View File

@ -35,7 +35,23 @@
namespace cpdoccore {
using namespace odf_types;
std::string DecodeBase64(const std::wstring & value1)
{
int nLength = 0;
unsigned char *pData = NULL;
std::string result;
std::string value(value1.begin(), value1.end());
NSFile::CBase64Converter::Decode(value.c_str(), value.length(), pData, nLength);
if (pData)
{
result = std::string((char*)pData, nLength);
delete []pData; pData = NULL;
}
return result;
}
namespace odf_reader {
style_instance::style_instance(

View File

@ -44,6 +44,9 @@
#include <iosfwd>
namespace cpdoccore {
std::string DecodeBase64(const std::wstring & value);
namespace odf_reader {
class styles_container;

View File

@ -149,9 +149,9 @@ void table_table_protection::add_attributes( const xml::attributes_wc_ptr & Attr
CP_APPLY_ATTR(L"loext:insert-rows", insert_rows);
CP_APPLY_ATTR(L"loext:delete-columns", delete_columns);
CP_APPLY_ATTR(L"loext:delete-rows", delete_rows);
CP_APPLY_ATTR(L"loext:format-columns", format_columns);
CP_APPLY_ATTR(L"loext:format-rows", format_rows);
CP_APPLY_ATTR(L"loext:format-cells", format_cells);
//CP_APPLY_ATTR(L"loext:format-columns", format_columns);
//CP_APPLY_ATTR(L"loext:format-rows", format_rows);
//CP_APPLY_ATTR(L"loext:format-cells", format_cells);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// table:table

View File

@ -811,10 +811,39 @@ void ECMADecryptor::Decrypt(unsigned char* data_inp, int size, unsigned char*&
}
}
//-----------------------------------------------------------------------------------------------------------
ECMAWriteProtect::ECMAWriteProtect()
void odfWriteProtect::SetPassword (const std::wstring &password_)
{
password = password_;
}
void ECMAWriteProtect::SetPassword (std::wstring password_)
void odfWriteProtect::SetProtectKey (const std::string &key)
{
protect_key = key;
}
void odfWriteProtect::SetProtectAlgorithm (const CRYPT_METHOD::_hashAlgorithm &alg)
{
hash = alg;
}
void odfWriteProtect::Generate()
{
_buf pPassword (password);
_buf empty (NULL, 0, false);
_buf pHashTest = HashAppend(empty, pPassword, hash);
protect_key = std::string((char*)pHashTest.ptr, pHashTest.size);
}
bool odfWriteProtect::Verify()
{
_buf pPassword (password);
_buf empty (NULL, 0, false);
_buf pHash (protect_key);
_buf pHashTest = HashAppend(empty, pPassword, hash);
return (pHashTest == pHash);
}
//----------------------------------------------------------------------------------------------------------
void ECMAWriteProtect::SetPassword (const std::wstring &password_)
{
password = password_;
}
@ -889,8 +918,6 @@ bool ECMAWriteProtect::Verify()
}
return (pHashTest == pHash);
}
//-----------------------------------------------------------------------------------------------------------
ECMAEncryptor::ECMAEncryptor()
{

View File

@ -133,14 +133,13 @@ struct _odfCryptData
CRYPT_METHOD::_hashAlgorithm checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
};
//---------------------------------------------------------------------------------------------------
class ECMAWriteProtect
{
public:
ECMAWriteProtect();
ECMAWriteProtect(){}
virtual ~ECMAWriteProtect(){}
void SetPassword (std::wstring password);
void SetPassword (const std::wstring &password);
void SetCryptData(_ecmaWriteProtectData &data);
void GetCryptData(_ecmaWriteProtectData &data);
@ -154,6 +153,24 @@ private:
_ecmaWriteProtectData data;
};
//---------------------------------------------------------------------------------------------------
class odfWriteProtect
{
public:
odfWriteProtect() : hash(CRYPT_METHOD::SHA1) {}
void SetPassword (const std::wstring & password);
void SetProtectKey (const std::string & protect_key);
void SetProtectAlgorithm (const CRYPT_METHOD::_hashAlgorithm & hash);
void Generate();
bool Verify();
private:
std::wstring password;
CRYPT_METHOD::_hashAlgorithm hash;
std::string protect_key;
};
//---------------------------------------------------------------------------------------------------
class ECMAEncryptor
{
public: