mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
.
This commit is contained in:
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
#include "../formulasconvert/formulasconvert.h"
|
#include "../formulasconvert/formulasconvert.h"
|
||||||
|
|
||||||
|
#include "../../../OfficeCryptReader/source/CryptTransform.h"
|
||||||
|
|
||||||
namespace cpdoccore {
|
namespace cpdoccore {
|
||||||
namespace oox {
|
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);
|
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
|
unsigned int xlsx_table_state::columns_count() const
|
||||||
|
|||||||
@ -332,22 +332,6 @@ bool odf_document::Impl::decrypt_folder (const std::wstring &password, const std
|
|||||||
}
|
}
|
||||||
return result;
|
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 )
|
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());
|
manifest_encryption_data* encryption_data = dynamic_cast<manifest_encryption_data*>(element.get());
|
||||||
|
|||||||
@ -35,7 +35,23 @@
|
|||||||
namespace cpdoccore {
|
namespace cpdoccore {
|
||||||
|
|
||||||
using namespace odf_types;
|
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 {
|
namespace odf_reader {
|
||||||
|
|
||||||
style_instance::style_instance(
|
style_instance::style_instance(
|
||||||
|
|||||||
@ -44,6 +44,9 @@
|
|||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
namespace cpdoccore {
|
namespace cpdoccore {
|
||||||
|
|
||||||
|
std::string DecodeBase64(const std::wstring & value);
|
||||||
|
|
||||||
namespace odf_reader {
|
namespace odf_reader {
|
||||||
|
|
||||||
class styles_container;
|
class styles_container;
|
||||||
|
|||||||
@ -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:insert-rows", insert_rows);
|
||||||
CP_APPLY_ATTR(L"loext:delete-columns", delete_columns);
|
CP_APPLY_ATTR(L"loext:delete-columns", delete_columns);
|
||||||
CP_APPLY_ATTR(L"loext:delete-rows", delete_rows);
|
CP_APPLY_ATTR(L"loext:delete-rows", delete_rows);
|
||||||
CP_APPLY_ATTR(L"loext:format-columns", format_columns);
|
//CP_APPLY_ATTR(L"loext:format-columns", format_columns);
|
||||||
CP_APPLY_ATTR(L"loext:format-rows", format_rows);
|
//CP_APPLY_ATTR(L"loext:format-rows", format_rows);
|
||||||
CP_APPLY_ATTR(L"loext:format-cells", format_cells);
|
//CP_APPLY_ATTR(L"loext:format-cells", format_cells);
|
||||||
}
|
}
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// table:table
|
// table:table
|
||||||
|
|||||||
@ -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_;
|
password = password_;
|
||||||
}
|
}
|
||||||
@ -889,8 +918,6 @@ bool ECMAWriteProtect::Verify()
|
|||||||
}
|
}
|
||||||
return (pHashTest == pHash);
|
return (pHashTest == pHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------------
|
||||||
ECMAEncryptor::ECMAEncryptor()
|
ECMAEncryptor::ECMAEncryptor()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -133,14 +133,13 @@ struct _odfCryptData
|
|||||||
CRYPT_METHOD::_hashAlgorithm checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
|
CRYPT_METHOD::_hashAlgorithm checksum_hashAlgorithm = CRYPT_METHOD::SHA1;
|
||||||
};
|
};
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class ECMAWriteProtect
|
class ECMAWriteProtect
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ECMAWriteProtect();
|
ECMAWriteProtect(){}
|
||||||
virtual ~ECMAWriteProtect(){}
|
virtual ~ECMAWriteProtect(){}
|
||||||
|
|
||||||
void SetPassword (std::wstring password);
|
void SetPassword (const std::wstring &password);
|
||||||
|
|
||||||
void SetCryptData(_ecmaWriteProtectData &data);
|
void SetCryptData(_ecmaWriteProtectData &data);
|
||||||
void GetCryptData(_ecmaWriteProtectData &data);
|
void GetCryptData(_ecmaWriteProtectData &data);
|
||||||
@ -154,6 +153,24 @@ private:
|
|||||||
_ecmaWriteProtectData data;
|
_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
|
class ECMAEncryptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user