-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcrypto.hpp
60 lines (53 loc) · 1.41 KB
/
mcrypto.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef _BASE64_H_
#define _BASE64_H_
#include <openssl/evp.h>
/*
* A simple class to encode/decode a string using base64.
*/
class Base64Encoder
{
public:
Base64Encoder(void);
~Base64Encoder(void);
std::string encode(std::basic_string<unsigned char> &data);
std::basic_string<unsigned char> decode(std::string &b64string);
};
/*
* An enum to represent the strength of the SHA digest.
*/
enum SHAStrength {
sha1=0,
sha256=1
};
/*
* A simple class to generate SHA digests on input.
*/
class SHAEncoder
{
public:
SHAEncoder(SHAStrength strength=SHAStrength::sha1);
~SHAEncoder(void);
std::basic_string<unsigned char> quickdigest(std::basic_string<unsigned char> in);
private:
SHAStrength m_strength;
};
/*
* A simple class to encode/decode a string using the provided cipher.
* See EVP_CIPHER(3ssl) for all cipher types. If cipher_type is NULL,
* EVP_aes_256_cfb8() will be used.
*/
class AESEncryptor
{
public:
AESEncryptor(std::basic_string<unsigned char> &key,
std::basic_string<unsigned char> &iv,
const EVP_CIPHER *cipher_type = NULL);
~AESEncryptor(void);
std::basic_string<unsigned char> encrypt(std::string &plaintext);
std::string decrypt(std::basic_string<unsigned char> &ciphertext);
private:
std::basic_string<unsigned char> m_key;
std::basic_string<unsigned char> m_iv;
const EVP_CIPHER *m_cipher_type;
};
#endif