mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
fix encrypt with password
This commit is contained in:
@ -516,7 +516,12 @@ return 0;
|
||||
std::string sPathUtf8Old = U_TO_UTF8(m_pInternal->m_wsSrcPath);
|
||||
if (sPathUtf8Old == sPathUtf8New || NSSystemPath::NormalizePath(sPathUtf8Old) == NSSystemPath::NormalizePath(sPathUtf8New))
|
||||
{
|
||||
if (!m_pInternal->m_pPDFDocument->makeWritable(true))
|
||||
GString* owner_pswd = NSStrings::CreateString(sPassword);
|
||||
GString* user_pswd = NSStrings::CreateString(sPassword);
|
||||
bool bRes = m_pInternal->m_pPDFDocument->makeWritable(true, owner_pswd, user_pswd);
|
||||
delete owner_pswd;
|
||||
delete user_pswd;
|
||||
if (!bRes)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -655,7 +660,7 @@ return 0;
|
||||
|
||||
return m_pInternal->m_pPdfWriter->AddPage(nPageIndex);
|
||||
}
|
||||
bool CPdfReader::EditClose()
|
||||
bool CPdfReader::EditClose(const std::wstring& sPassword)
|
||||
{
|
||||
if (!m_pInternal->m_pPdfWriter || !m_pInternal->m_pPDFDocument)
|
||||
return false;
|
||||
@ -676,7 +681,11 @@ return 0;
|
||||
info.free();
|
||||
|
||||
bool bRes = m_pInternal->m_pPdfWriter->EditClose(sTrailer, sInfo);
|
||||
bRes &= m_pInternal->m_pPDFDocument->makeWritable(false);
|
||||
GString* owner_pswd = NSStrings::CreateString(sPassword);
|
||||
GString* user_pswd = NSStrings::CreateString(sPassword);
|
||||
bRes &= m_pInternal->m_pPDFDocument->makeWritable(false, owner_pswd, user_pswd);
|
||||
delete owner_pswd;
|
||||
delete user_pswd;
|
||||
|
||||
NSFile::CFileBinary oFile;
|
||||
if (oFile.OpenFile(m_pInternal->m_wsSrcPath))
|
||||
|
||||
@ -102,7 +102,7 @@ namespace PdfReader
|
||||
bool EditPage(int nPageIndex);
|
||||
bool DeletePage(int nPageIndex);
|
||||
bool AddPage(int nPageIndex);
|
||||
bool EditClose();
|
||||
bool EditClose(const std::wstring& sPassword);
|
||||
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
virtual BYTE* GetStructure();
|
||||
|
||||
@ -672,7 +672,7 @@ char *PDFDoc::getEmbeddedFileMem(int idx, int *size) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
GBool PDFDoc::makeWritable(bool bWritable)
|
||||
GBool PDFDoc::makeWritable(bool bWritable, GString* ownerPassword, GString* userPassword)
|
||||
{
|
||||
if (!str || !file)
|
||||
return gFalse;
|
||||
@ -765,7 +765,7 @@ GBool PDFDoc::makeWritable(bool bWritable)
|
||||
Object obj;
|
||||
obj.initNull();
|
||||
str = new FileStream(file, start, gFalse, 0, &obj);
|
||||
ok = setup(NULL, NULL);
|
||||
ok = setup(ownerPassword, userPassword);
|
||||
|
||||
return bRes;
|
||||
}
|
||||
|
||||
@ -190,7 +190,8 @@ public:
|
||||
GBool saveEmbeddedFile(int idx, const wchar_t *path, int pathLen);
|
||||
#endif
|
||||
char *getEmbeddedFileMem(int idx, int *size);
|
||||
GBool makeWritable(bool bWritable);
|
||||
GBool makeWritable(bool bWritable, GString *ownerPassword = NULL,
|
||||
GString *userPassword = NULL);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user