LibreOffice Module comphelper (master)  1
docpasswordhelper.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_COMPHELPER_DOCPASSWORDHELPER_HXX
21 #define INCLUDED_COMPHELPER_DOCPASSWORDHELPER_HXX
22 
24 #include <string_view>
25 #include <vector>
27 #include <comphelper/hash.hxx>
28 
29 namespace com::sun::star::task { class XInteractionHandler; }
30 namespace com::sun::star::beans { struct PropertyValue; }
31 namespace com::sun::star::beans { struct NamedValue; }
32 
33 namespace comphelper {
34 
36 {
37  OK,
39  Abort
40 };
41 
42 
50 {
51 public:
52  virtual ~IDocPasswordVerifier();
53 
73  virtual DocPasswordVerifierResult verifyPassword( const OUString& rPassword, css::uno::Sequence< css::beans::NamedValue >& o_rEncryptionData ) = 0;
74 
89  virtual DocPasswordVerifierResult verifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& o_rEncryptionData ) = 0;
90 
91 };
92 
93 
97 {
98 public:
99 
100 
113  static css::uno::Sequence< css::beans::PropertyValue >
114  GenerateNewModifyPasswordInfo( std::u16string_view aPassword );
115 
116 
131  static bool IsModifyPasswordCorrect(
132  std::u16string_view aPassword,
133  const css::uno::Sequence< css::beans::PropertyValue >& aInfo );
134 
135 
146  static sal_uInt32 GetWordHashAsUINT32(
147  const OUString& aString );
148 
149 
165  static sal_uInt16 GetXLHashAsUINT16(
166  std::u16string_view aString,
167  rtl_TextEncoding nEnc = RTL_TEXTENCODING_UTF8 );
168 
169 
181  static css::uno::Sequence< sal_Int8 > GetXLHashAsSequence(
182  std::u16string_view aString );
183 
184 
222  static css::uno::Sequence<sal_Int8> GetOoxHashAsSequence(
223  const OUString& rPassword,
224  const OUString& rSaltValue,
225  sal_uInt32 nSpinCount,
226  comphelper::Hash::IterCount eIterCount,
227  std::u16string_view rAlgorithmName);
228 
229 
268  static OUString GetOoxHashAsBase64(
269  const OUString& rPassword,
270  const OUString& rSaltValue,
271  sal_uInt32 nSpinCount,
272  comphelper::Hash::IterCount eIterCount,
273  std::u16string_view rAlgorithmName);
274 
275 
312  static std::vector<unsigned char> GetOoxHashAsVector(
313  const OUString& rPassword,
314  const std::vector<unsigned char>& rSaltValue,
315  sal_uInt32 nSpinCount,
316  comphelper::Hash::IterCount eIterCount,
317  std::u16string_view rAlgorithmName);
318 
319 
324  static css::uno::Sequence< sal_Int8 > GenerateRandomByteSequence(
325  sal_Int32 nLength );
326 
327 
332  static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
333  const OUString& aPassword,
334  const css::uno::Sequence< sal_Int8 >& aDocId );
335 
336 
341  static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
342  const sal_uInt16 pPassData[16],
343  const css::uno::Sequence< sal_Int8 >& aDocId );
344 
349  static css::uno::Sequence< sal_Int8 > GenerateStd97Key(
350  const sal_uInt16 pPassData[16],
351  const sal_uInt8 pDocId[16] );
352 
353 
407  static css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword(
408  IDocPasswordVerifier& rVerifier,
409  const css::uno::Sequence< css::beans::NamedValue >& rMediaEncData,
410  const OUString& rMediaPassword,
411  const css::uno::Reference< css::task::XInteractionHandler >& rxInteractHandler,
412  const OUString& rDocumentUrl,
413  DocPasswordRequestType eRequestType,
414  const ::std::vector< OUString >* pDefaultPasswords = nullptr,
415  bool* pbIsDefaultPassword = nullptr );
416 
417  static css::uno::Sequence< css::beans::NamedValue > decryptGpgSession(
418  const css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > >& rGpgProperties);
419 
420 private:
422 };
423 
424 
425 } // namespace comphelper
426 
427 #endif
428 
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper that asks for a document password and checks its validity.
DocPasswordRequestType
Selects which UNO document password request type to use.
unsigned char sal_uInt8
Base class for a password verifier used by the DocPasswordHelper class below.
#define COMPHELPER_DLLPUBLIC
sal_Int32 nLength