-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathencrypt.h
63 lines (55 loc) · 1.75 KB
/
encrypt.h
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
61
62
63
//
// encrypt.h - encryption/decryption interface
//
// leccore library, part of the liblec library
// Copyright (c) 2019 Alec Musasa (alecmus at live dot com)
//
// Released under the MIT license. For full details see the
// file LICENSE.txt
//
#pragma once
#if defined(LECCORE_EXPORTS)
#include "leccore.h"
#else
#include <liblec/leccore.h>
#endif
#include <string>
namespace liblec {
namespace leccore {
/// <summary>256bit AES encryption class.</summary>
class leccore_api aes {
public:
/// <summary>Constructor.</summary>
/// <param name="key">The key to use for encryption. This must be kept private.</param>
/// <param name="iv">The initialization vector to use. This must be unique.</param>
aes(const std::string& key,
const std::string& iv);
~aes();
/// <summary>Encrypt data.</summary>
/// <param name="input">The data to be encrypted.</param>
/// <param name="encrypted">The encrypted data.</param>
/// <param name="error">Error information.</param>
/// <returns>Returns true if successful, else false.</returns>
[[nodiscard]]
bool encrypt(const std::string& input,
std::string& encrypted,
std::string& error);
/// <summary>Decrypt data.</summary>
/// <param name="input">The data to be decrypted.</param>
/// <param name="decrypted">The decrypted data.</param>
/// <param name="error">Error information.</param>
/// <returns>Returns true if successful, else false.</returns>
[[nodiscard]]
bool decrypt(const std::string& input,
std::string& decrypted,
std::string& error);
private:
class impl;
impl& _d;
// Default constructor and copying an object of this class are not allowed.
aes() = delete;
aes(const aes&) = delete;
aes& operator=(const aes&) = delete;
};
}
}