Can someone explain how to decrypt the .keys file?
Specifically, the load_keys function within the wallet2.cpp in the source. Can explain the logic behind it and the procedure. (Not that fluent in C)
void wallet2::load_keys(const std::string& keys_file_name, const std::string& password)
{
wallet2::keys_file_data keys_file_data;
std::string buf;
1 bool r = epee::file_io_utils::load_file_to_string(keys_file_name, buf);
THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, keys_file_name);
// Decrypt the contents
2 r = ::serialization::parse_binary(buf, keys_file_data);
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "internal error: failed to deserialize \"" + keys_file_name + '\"');
crypto::chacha8_key key;
3 crypto::generate_chacha8_key(password, key);
std::string account_data;
account_data.resize(keys_file_data.account_data.size());
4 crypto::chacha8(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
.....
I labeled some lines of the code above:
1. Loads the data file into a memory buffer
2. Parses the memory buffer into a data object
3. Derives a chacha8 decryption key from the password (this uses the CryptoNight slow hash for key stretching, which greatly limits the possibility of brute forcing).
4. Decrypts the data using the decryption key
The unlabeled lines in the code are error checking, memory management, etc.
Ok, that clears some things up.
But what do you mean by 2. "Parse the memory buffer into a data object"?
I can read the .keys file in and store it as a string but how do I do the 2nd step of parsing? What type of characters is it stored as?