|
@ -169,14 +169,40 @@ h128 SecretStore::readKey(std::string const& _file, bool _deleteFile) |
|
|
return h128(); |
|
|
return h128(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string SecretStore::encrypt(bytes const& _v, std::string const& _pass) |
|
|
void SecretStore::recode(h128 const& _uuid, string const& _pass, KDF _kdf) |
|
|
|
|
|
{ |
|
|
|
|
|
m_keys[_uuid].first = encrypt(secret(_uuid, [&](){ return _pass; }), _pass, _kdf); |
|
|
|
|
|
save(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string SecretStore::encrypt(bytes const& _v, std::string const& _pass, KDF _kdf) |
|
|
{ |
|
|
{ |
|
|
js::mObject ret; |
|
|
js::mObject ret; |
|
|
|
|
|
|
|
|
// KDF info
|
|
|
// KDF info
|
|
|
unsigned dklen = 16; |
|
|
unsigned dklen = 16; |
|
|
unsigned iterations = 262144; |
|
|
|
|
|
bytes salt = h256::random().asBytes(); |
|
|
bytes salt = h256::random().asBytes(); |
|
|
|
|
|
bytes derivedKey; |
|
|
|
|
|
if (_kdf == KDF::Scrypt) |
|
|
|
|
|
{ |
|
|
|
|
|
unsigned iterations = 262144; |
|
|
|
|
|
unsigned p = 262144; |
|
|
|
|
|
unsigned r = 262144; |
|
|
|
|
|
ret["kdf"] = "scrypt"; |
|
|
|
|
|
{ |
|
|
|
|
|
js::mObject params; |
|
|
|
|
|
params["n"] = (int)iterations; |
|
|
|
|
|
params["p"] = 1; |
|
|
|
|
|
params["r"] = 8; |
|
|
|
|
|
params["dklen"] = (int)dklen; |
|
|
|
|
|
params["salt"] = toHex(salt); |
|
|
|
|
|
ret["kdfparams"] = params; |
|
|
|
|
|
} |
|
|
|
|
|
derivedKey = scrypt(_pass, salt, iterations, p, r, dklen); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
unsigned iterations = 262144; |
|
|
ret["kdf"] = "pbkdf2"; |
|
|
ret["kdf"] = "pbkdf2"; |
|
|
{ |
|
|
{ |
|
|
js::mObject params; |
|
|
js::mObject params; |
|
@ -186,7 +212,8 @@ std::string SecretStore::encrypt(bytes const& _v, std::string const& _pass) |
|
|
params["dklen"] = (int)dklen; |
|
|
params["dklen"] = (int)dklen; |
|
|
ret["kdfparams"] = params; |
|
|
ret["kdfparams"] = params; |
|
|
} |
|
|
} |
|
|
bytes derivedKey = pbkdf2(_pass, salt, iterations, dklen); |
|
|
derivedKey = pbkdf2(_pass, salt, iterations, dklen); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// cipher info
|
|
|
// cipher info
|
|
|
ret["cipher"] = "aes-128-cbc"; |
|
|
ret["cipher"] = "aes-128-cbc"; |
|
|