sipxportlib  Version 3.3
UtlCryptoKeyRsa.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2008 SIPez LLC.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // Copyright (C) 2008 Mutualink, Inc.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 // Author: Sergey Kostanbaev <Sergey DOT Kostanbaev AT sipez DOT com>
15 
16 #ifndef _UtlCryptoKeyRsa_h_
17 #define _UtlCryptoKeyRsa_h_
18 
19 // SYSTEM INCLUDES
20 // APPLICATION INCLUDES
21 #include "utl/UtlCryptoKey.h"
22 
23 // DEFINES
24 // MACROS
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // STRUCTS
28 // TYPEDEFS
29 // FORWARD DECLARATIONS
30 
35 {
36 /* //////////////////////////////// PUBLIC //////////////////////////////// */
37 public:
38 
39 /* =============================== CREATORS =============================== */
41 
42 
45 
48 
50 
51 /* ============================= MANIPULATORS ============================= */
53 
54 
55  int generateKey();
56 
57  int importFromFile(const char* pFilename);
58 
59  int getMaxEncryptedSize(int srcLen) const;
60 
62  int encrypt(const unsigned char* pSrc,
63  int srcLen,
64  unsigned char* pDest,
65  int* pDestLen) const;
66 
67  //UtlCryptoData* encrypt(const unsigned char* pSrc, int srcLen) const
68  //{ return UtlCryptoKey::encrypt(pSrc, srcLen); }
69 
70  int getMaxDecryptedSize(int srcLen) const;
71 
73  int decrypt(const unsigned char* pSrc,
74  int srcLen,
75  unsigned char* pDest,
76  int* pDestLen) const;
77 
79  int getMaxSignatureSize(int srcLen) const;
80 
82  int sign(const unsigned char* pSrc,
83  int srcLen,
84  unsigned char* pDest,
85  int* pDestLen) const;
86 
88  int verify(const unsigned char* pSrc,
89  int srcLen,
90  const unsigned char* pSig,
91  int sigLen) const;
92 
94  int encryptPrivate(const unsigned char* pSrc,
95  int srcLen,
96  unsigned char* pDest,
97  int* pDestLen) const;
108  int decryptPrivate(const unsigned char* pSrc,
110  int srcLen,
111  unsigned char* pDest,
112  int* pDestLen) const;
123  int encryptPublic(const unsigned char* pSrc,
125  int srcLen,
126  unsigned char* pDest,
127  int* pDestLen) const;
138  int decryptPublic(const unsigned char* pSrc,
140  int srcLen,
141  unsigned char* pDest,
142  int* pDestLen) const;
154 
155 /* ============================== ACCESSORS =============================== */
157 
158 
160 
161 /* =============================== INQUIRY ================================ */
163 
164 
166  UtlString output() const;
167 
168 
170 
171 /* ////////////////////////////// PROTECTED /////////////////////////////// */
172 protected:
173 
174 
175 /* /////////////////////////////// PRIVATE //////////////////////////////// */
176 private:
177 
178  void clearKey();
179  RSA* mpRsa;
180 };
181 
182 
183 /* ============================ INLINE METHODS ============================ */
184 
185 #endif // _UtlCryptoKeyRsa_h_
int decryptPublic(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Decrypts the given source data with the current PUBLIC key.
UtlCryptoKeyRsa()
Constructor.
struct rsa_st RSA
Definition: UtlCryptoKey.h:24
A generic cryptography key base class.
Definition: UtlCryptoKey.h:36
int encryptPublic(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Encrypts the given source data with the current PUBLIC key.
int encryptPrivate(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Decrypts the given source data with the current PRIVATE key.
~UtlCryptoKeyRsa()
Destructor.
int encrypt(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Encrypts the given source data with the current key.
int verify(const unsigned char *pSrc, int srcLen, const unsigned char *pSig, int sigLen) const
Verifies that the signature is valid for the source data.
Definition: UtlString.h:48
int decrypt(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Decrypts the given source data with the current key.
int getMaxEncryptedSize(int srcLen) const
Returns the max encrypted size of srcLen bytes from encrypt()
int decryptPrivate(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Decrypts the given source data with the current PRIVATE key.
int getMaxSignatureSize(int srcLen) const
Returns the max size of a signature that sign() will return.
int getMaxDecryptedSize(int srcLen) const
Returns the max decrypted size of srcLen bytes from decrypt()
int generateKey()
Generates a new RSA private/public key pair.
int sign(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Signs source data.
UtlString output() const
Get humane-readable describe.
int importFromFile(const char *pFilename)
Imports a key from the given file.
Rsa private/public keypairs.
Definition: UtlCryptoKeyRsa.h:34