-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_data.hpp
61 lines (54 loc) · 1.41 KB
/
single_data.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
61
#include <Siv3d.hpp>
/**
* @brief 1つの項目のデータを定めた構造体
* @details パスワードは暗号の状態は16進数文字列、復号化された状態では通常の文字列である
*
*/
class single_data {
public:
/** サービス名 */
String service_name;
/** ユーザー名 */
String user_name;
/** パスワード */
String password;
/**
* @brief コンストラクタ
*
* @param id ID
* @param service_name サービス名
* @param user_name ユーザー名
* @param password パスワード
*/
single_data(
String service_name,
String user_name,
String password):
service_name(service_name),
user_name(user_name),
password(password)
{}
/**
* @brief デフォルトコンストラクタ
*
*/
single_data() {}
template <class Archive>
void SIV3D_SERIALIZE(Archive& archive) {
archive(service_name, user_name, password);
}
void encrypt(String key) {
String tmp = U"";
for (int i = 0; i < (password.length() + 15) / 16; i++) {
tmp += aes256_encrypt(password.substr(i * 16, 16), key);
}
password = tmp;
}
void decrypt(String key) {
String tmp = U"";
for (int i = 0; i < password.length() / 512; i++) {
tmp += aes256_decrypt(password.substr(i * 512, 512), key).substr(0, 16);
}
password = tmp;
}
};