14 #ifndef _UtlCryptoKey_h_ 15 #define _UtlCryptoKey_h_ 24 typedef struct rsa_st
RSA;
88 virtual int encrypt(
const unsigned char* pSrc,
91 int* pDestLen)
const = 0;
118 virtual int decrypt(
const unsigned char* pSrc,
120 unsigned char* pDest,
121 int* pDestLen)
const = 0;
147 virtual int sign(
const unsigned char* pSrc,
149 unsigned char* pDest,
150 int* pDestLen)
const;
172 virtual int verify(
const unsigned char* pSrc,
175 const unsigned char* pSig,
213 unsigned char* pDest,
241 unsigned char* pDest,
269 unsigned char* pDest,
283 unsigned char* pDest,
322 static bool isBase64(
unsigned char c);
329 mutable unsigned long mLastErr;
332 static const EVP_MD* spMdAlg;
375 #endif // Include guard virtual int getMaxEncryptedSize(int srcLen) const =0
Returns the max encrypted size of srcLen bytes from encrypt()
This is a symmetric key.
Definition: UtlCryptoKey.h:45
static int getMaxBase64EncodedSize(int srcLen)
Returns the max base64-encoded size of srcLen bytes from base64Encode.
struct rsa_st RSA
Definition: UtlCryptoKey.h:24
A generic cryptography key base class.
Definition: UtlCryptoKey.h:36
virtual int importFromFile(const char *pFilename)
Imports a key from the given file.
static int getMaxDigestSize(int srcLen)
Returns the max size of a digest that computeDigest() will return.
bool isValid() const
Definition: UtlCryptoKey.h:338
virtual 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.
UtlCryptoKey()
Constructor.
virtual int loadBinaryKey(const unsigned char *pSrc, int srcLen)
Loads a binary key value.
static int getDigestAlgType()
Returns the digest algorithm type that computeDigest() will return.
virtual int generateKey()=0
Generates a new RSA private/public key pair.
static int base64Encode(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen)
Encodes the given binary data in base64 format.
struct env_md_st EVP_MD
Definition: UtlCryptoKey.h:26
virtual UtlString output() const
virtual ~UtlCryptoKey()
Destructor.
virtual UtlCryptoData * getBinaryKey() const
Retrieves a binary key value (for later use by loadBinaryKey)
Crypto data operations.
Definition: UtlCryptoData.h:37
static int getBase64Idx(unsigned char c)
Decode base64 character.
static int getMaxBase64DecodedSize(int srcLen)
Returns the max decoded size of srcLen bytes from base64Decode.
static int base64Decode(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen)
Decodes the given base64 data into binary format.
virtual int encrypt(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const =0
Encrypts the given source data with the current key.
Number of key types defined.
Definition: UtlCryptoKey.h:48
KeyType setKeyType(KeyType type)
Definition: UtlCryptoKey.h:368
Definition: UtlString.h:48
bool isPublic() const
Definition: UtlCryptoKey.h:348
virtual int decrypt(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const =0
Decrypts the given source data with the current key.
This is a private key (also includes a public key)
Definition: UtlCryptoKey.h:46
virtual int getMaxDecryptedSize(int srcLen) const =0
Returns the max decrypted size of srcLen bytes from decrypt()
static const char sBase64Chars[]
Set of base64 chars.
Definition: UtlCryptoKey.h:324
unsigned long setLastError(unsigned long err) const
static int computeDigest(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen)
Computes message digest (MD) of given data.
KeyType
What type of Key is this?
Definition: UtlCryptoKey.h:42
static bool isBase64(unsigned char c)
Returns true if the given char is a base64 char.
virtual int sign(const unsigned char *pSrc, int srcLen, unsigned char *pDest, int *pDestLen) const
Signs source data.
bool isPrivate() const
Definition: UtlCryptoKey.h:343
This is only a public key.
Definition: UtlCryptoKey.h:47
This key is not currently valid.
Definition: UtlCryptoKey.h:44
virtual int getMaxSignatureSize(int srcLen) const
Signing & verifying.
KeyType getKeyType() const
Definition: UtlCryptoKey.h:358
struct evp_cipher_st EVP_CIPHER
Definition: UtlCryptoKey.h:25
bool isSymmetric() const
Definition: UtlCryptoKey.h:353
unsigned long getLastError() const
Definition: UtlCryptoKey.h:363