|
6 | 6 | #include <vector> |
7 | 7 | #include <string> |
8 | 8 |
|
9 | | -#pragma comment(lib, "libeay32") |
| 9 | +#pragma comment(lib, "libssl_static") |
| 10 | +#pragma comment(lib, "libcrypto_static") |
| 11 | +#pragma comment(lib, "ws2_32") |
10 | 12 |
|
11 | 13 | namespace |
12 | 14 | { |
@@ -69,11 +71,12 @@ namespace |
69 | 71 | auto cipher = EVP_aes_256_cbc(); |
70 | 72 | auto ctx = EVP_CIPHER_CTX_new(); |
71 | 73 |
|
72 | | - auto num_blocks = plaintext.size() / cipher->block_size; |
73 | | - if (plaintext.size() % cipher->block_size != 0) { |
| 74 | + auto cipher_block_size = EVP_CIPHER_block_size(cipher); |
| 75 | + auto num_blocks = plaintext.size() / cipher_block_size; |
| 76 | + if (plaintext.size() % cipher_block_size != 0) { |
74 | 77 | ++num_blocks; |
75 | 78 | } |
76 | | - auto out_plaintext = std::vector<uint8_t>(cipher->block_size * num_blocks); |
| 79 | + auto out_plaintext = std::vector<uint8_t>(cipher_block_size * num_blocks); |
77 | 80 |
|
78 | 81 | EVP_CIPHER_CTX_init(ctx); |
79 | 82 |
|
@@ -120,8 +123,11 @@ namespace |
120 | 123 | auto cipher = EVP_aes_256_cbc(); |
121 | 124 | auto md = EVP_sha1(); |
122 | 125 |
|
123 | | - out_key.resize(cipher->key_len); |
124 | | - out_initialization_vector.resize(cipher->iv_len); |
| 126 | + auto cipher_key_length = EVP_CIPHER_key_length(cipher); |
| 127 | + auto cipher_iv_length = EVP_CIPHER_iv_length(cipher); |
| 128 | + |
| 129 | + out_key.resize(cipher_key_length); |
| 130 | + out_initialization_vector.resize(cipher_iv_length); |
125 | 131 |
|
126 | 132 | auto derived_key_length = EVP_BytesToKey( |
127 | 133 | cipher, |
@@ -171,9 +177,9 @@ namespace |
171 | 177 | /// <param name="is_encrypting">Determines if data should be encrypted or decrypted</param> |
172 | 178 | /// <returns>Encrypted or decrypted data</returns> |
173 | 179 | std::vector<uint8_t> EncryptOrDecryptData( |
174 | | - const std::vector<uint8_t>& data, |
175 | | - const std::string& machine_guid, |
176 | | - const std::string& salt_string, |
| 180 | + const std::vector<uint8_t> &data, |
| 181 | + const std::string &machine_guid, |
| 182 | + const std::string &salt_string, |
177 | 183 | bool is_encrypting) |
178 | 184 | { |
179 | 185 | std::vector<uint8_t> salt_bytes; |
@@ -202,17 +208,17 @@ namespace UserPreferences |
202 | 208 | namespace Encryption |
203 | 209 | { |
204 | 210 | std::vector<uint8_t> DecryptData( |
205 | | - const std::vector<uint8_t>& encrypted_data, |
206 | | - const std::string& machine_guid, |
207 | | - const std::string& salt_string) |
| 211 | + const std::vector<uint8_t> &encrypted_data, |
| 212 | + const std::string &machine_guid, |
| 213 | + const std::string &salt_string) |
208 | 214 | { |
209 | 215 | return EncryptOrDecryptData(encrypted_data, machine_guid, salt_string, false); |
210 | 216 | } |
211 | 217 |
|
212 | 218 | std::vector<uint8_t> EncryptData( |
213 | | - const std::vector<uint8_t>& plaintext_data, |
214 | | - const std::string& machine_guid, |
215 | | - const std::string& salt_string) |
| 219 | + const std::vector<uint8_t> &plaintext_data, |
| 220 | + const std::string &machine_guid, |
| 221 | + const std::string &salt_string) |
216 | 222 | { |
217 | 223 | return EncryptOrDecryptData(plaintext_data, machine_guid, salt_string, true); |
218 | 224 | } |
|
0 commit comments