1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 #include <rtl/cipher.h>
14 #include <rtl/ustring.hxx>
16 #include <pdf/IPDFEncryptor.hxx>
18 namespace com::sun::star::uno
20 template <typename
> class Reference
;
25 class EncryptionHashTransporter
;
27 class PDFEncryptor
: public IPDFEncryptor
30 /* the numerical value of the access permissions, according to PDF spec, must be signed */
31 sal_Int32 m_nAccessPermissions
= 0;
33 /* The encryption key, formed with the user password according to algorithm 3.2,
34 * maximum length is 16 bytes + 3 + 2 for 128 bit security */
36 sal_Int32 m_nKeyLength
= 0; // key length, 16 or 5
37 sal_Int32 m_nRC4KeyLength
= 0; // key length, 16 or 10, to be input to the algorithm 3.1
39 /* used to cipher the stream data and for password management */
40 rtlCipher m_aCipher
= nullptr;
46 sal_Int32
getVersion() override
{ return 2; };
47 sal_Int32
getRevision() override
{ return 3; };
49 sal_Int32
getAccessPermissions() override
{ return m_nAccessPermissions
; }
50 bool isMetadataEncrypted() override
{ return false; }
51 sal_Int32
getKeyLength() override
{ return m_nKeyLength
; }
52 sal_Int32
getRC4KeyLength() { return m_nRC4KeyLength
; }
54 static void initEncryption(EncryptionHashTransporter
& rEncryptionHashTransporter
,
55 const OUString
& i_rOwnerPassword
, const OUString
& i_rUserPassword
);
57 bool prepareEncryption(
58 const css::uno::Reference
<css::beans::XMaterialHolder
>& xEncryptionMaterialHolder
,
59 PDFEncryptionProperties
& rProperties
) override
;
61 void setupKeysAndCheck(PDFEncryptionProperties
& rProperties
) override
;
63 void setupEncryption(std::vector
<sal_uInt8
>& rEncryptionKey
, sal_Int32 nObject
) override
;
65 void encrypt(const void* pInput
, sal_uInt64 nInputSize
, std::vector
<sal_uInt8
>& rOutput
,
66 sal_uInt64 nOutputSize
) override
;
70 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */