~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/source_exporter/wxPdfDocument/include/wx/pdfencrypt.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////////
 
2
// Name:        pdfencrypt.h
 
3
// Purpose:     
 
4
// Author:      Ulrich Telle
 
5
// Modified by:
 
6
// Created:     2005-08-16
 
7
// Copyright:   (c) Ulrich Telle
 
8
// Licence:     wxWindows licence
 
9
///////////////////////////////////////////////////////////////////////////////
 
10
 
 
11
/// \file pdfencrypt.h Interface of the wxPdfFont class
 
12
 
 
13
#ifndef _PDFENCRYPT_H_
 
14
#define _PDFENCRYPT_H_
 
15
 
 
16
// wxWidgets headers
 
17
#include <wx/string.h>
 
18
#include <wx/wfstream.h>
 
19
 
 
20
#include "wx/pdfdocdef.h"
 
21
#include "wx/pdfrijndael.h"
 
22
 
 
23
/// Class representing PDF encryption methods. (For internal use only)
 
24
class WXDLLIMPEXP_PDFDOC wxPdfEncrypt
 
25
{
 
26
public:
 
27
  /// Default constructor
 
28
  wxPdfEncrypt(int revision = 2, int keyLength = 40);
 
29
 
 
30
  /// Default destructor
 
31
  virtual ~wxPdfEncrypt();
 
32
 
 
33
  /// Generate encryption key from user and owner passwords and protection key
 
34
  void GenerateEncryptionKey(const wxString& userPassword,
 
35
                             const wxString& ownerPassword,
 
36
                             int protection);
 
37
 
 
38
  bool Authenticate(const wxString& documentID, const wxString& password,
 
39
                    const wxString& uValue, const wxString& oValue,
 
40
                    int pValue, int lengthValue, int rValue);
 
41
 
 
42
  /// Get the U object value (user)
 
43
  const unsigned char* GetUValue() const { return m_uValue; }
 
44
 
 
45
  /// Get the O object value (owner)
 
46
  const unsigned char* GetOValue() const { return m_oValue; }
 
47
 
 
48
  /// Get the P object value (protection)
 
49
  int GetPValue() const { return m_pValue; }
 
50
 
 
51
  /// Get the revision number of the encryption method
 
52
  int GetRevision() const { return m_rValue; }
 
53
 
 
54
  /// Get the key length of the encryption key in bits
 
55
  int GetKeyLength() const { return m_keyLength*8; }
 
56
 
 
57
  /// Encrypt a wxString
 
58
  void Encrypt(int n, int g, wxString& str);
 
59
 
 
60
  /// Encrypt a character string
 
61
  void Encrypt(int n, int g, unsigned char* str, int len);
 
62
 
 
63
  /// Calculate stream size
 
64
  int CalculateStreamLength(int length);
 
65
 
 
66
  /// Calculate stream offset
 
67
  int CalculateStreamOffset();
 
68
 
 
69
  /// Create document id
 
70
  wxString CreateDocumentId();
 
71
 
 
72
  /// Get document id
 
73
  wxString GetDocumentId() const { return m_documentId; }
 
74
 
 
75
protected:
 
76
  /// Pad a password to 32 characters
 
77
  void PadPassword(const wxString& password, unsigned char pswd[32]);
 
78
 
 
79
  /// Compute owner key
 
80
  void ComputeOwnerKey(unsigned char userPad[32], unsigned char ownerPad[32],
 
81
                       int keylength, int revision, bool authenticate,
 
82
                       unsigned char ownerKey[32]);
 
83
 
 
84
  /// Compute encryption key and user key
 
85
  void ComputeEncryptionKey(const wxString& documentID,
 
86
                            unsigned char userPad[32], unsigned char ownerKey[32],
 
87
                            int pValue, int keyLength, int revision,
 
88
                            unsigned char userKey[32]);
 
89
 
 
90
  /// Check two keys for equality
 
91
  bool CheckKey(unsigned char key1[32], unsigned char key2[32]);
 
92
 
 
93
  /// RC4 encryption
 
94
  void RC4(unsigned char* key, int keylen,
 
95
           unsigned char* textin, int textlen,
 
96
           unsigned char* textout);
 
97
 
 
98
  /// Calculate the binary MD5 message digest of the given data
 
99
  void GetMD5Binary(const unsigned char* data, int length, unsigned char* digest);
 
100
 
 
101
  /// AES encryption
 
102
  void AES(unsigned char* key, int WXUNUSED(keylen),
 
103
           unsigned char* textin, int textlen,
 
104
           unsigned char* textout);
 
105
 
 
106
  /// Generate initial vector
 
107
  void GenerateInitialVector(unsigned char iv[16]);
 
108
 
 
109
private:
 
110
  wxString       m_documentId;         ///< Document ID
 
111
  unsigned char  m_uValue[32];         ///< U entry in pdf document
 
112
  unsigned char  m_oValue[32];         ///< O entry in pdf document
 
113
  int            m_pValue;             ///< P entry in pdf document
 
114
  int            m_rValue;             ///< Revision
 
115
  unsigned char  m_encryptionKey[16];  ///< Encryption key
 
116
  int            m_keyLength;          ///< Length of encryption key
 
117
  unsigned char  m_rc4key[16];         ///< last RC4 key
 
118
  unsigned char  m_rc4last[256];       ///< last RC4 state table
 
119
 
 
120
  wxPdfRijndael* m_aes;                ///< AES encryptor
 
121
};
 
122
 
 
123
#endif