This commit is contained in:
parent
bdb8f0aac9
commit
1b6237b9fc
@ -27,6 +27,7 @@
|
|||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
#include "ui/mgmt_app_config.hpp"
|
#include "ui/mgmt_app_config.hpp"
|
||||||
#include "utils/common.hpp"
|
#include "utils/common.hpp"
|
||||||
|
#include "utils/config.hpp"
|
||||||
#include "utils/error_utils.hpp"
|
#include "utils/error_utils.hpp"
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
#include "utils/hash.hpp"
|
#include "utils/hash.hpp"
|
||||||
@ -36,13 +37,15 @@
|
|||||||
namespace {
|
namespace {
|
||||||
[[nodiscard]] auto decrypt(std::string_view data, std::string_view password)
|
[[nodiscard]] auto decrypt(std::string_view data, std::string_view password)
|
||||||
-> std::string {
|
-> std::string {
|
||||||
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto decoded = macaron::Base64::Decode(data);
|
auto decoded = macaron::Base64::Decode(data);
|
||||||
repertory::data_buffer buffer(decoded.size());
|
repertory::data_buffer buffer(decoded.size());
|
||||||
|
|
||||||
auto key = repertory::utils::encryption::create_hash_blake2b_256(password);
|
auto key = repertory::utils::encryption::create_hash_blake2b_256(password);
|
||||||
|
|
||||||
std::uint64_t size{};
|
unsigned long long size{};
|
||||||
crypto_aead_xchacha20poly1305_ietf_decrypt(
|
auto res = crypto_aead_xchacha20poly1305_ietf_decrypt(
|
||||||
reinterpret_cast<unsigned char *>(buffer.data()), &size, nullptr,
|
reinterpret_cast<unsigned char *>(buffer.data()), &size, nullptr,
|
||||||
reinterpret_cast<const unsigned char *>(
|
reinterpret_cast<const unsigned char *>(
|
||||||
&decoded.at(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES)),
|
&decoded.at(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES)),
|
||||||
@ -50,6 +53,10 @@ namespace {
|
|||||||
reinterpret_cast<const unsigned char *>(REPERTORY.data()), 9U,
|
reinterpret_cast<const unsigned char *>(REPERTORY.data()), 9U,
|
||||||
reinterpret_cast<const unsigned char *>(decoded.data()),
|
reinterpret_cast<const unsigned char *>(decoded.data()),
|
||||||
reinterpret_cast<const unsigned char *>(key.data()));
|
reinterpret_cast<const unsigned char *>(key.data()));
|
||||||
|
if (res != 0) {
|
||||||
|
throw repertory::utils::error::create_exception(function_name,
|
||||||
|
{"decryption failed"});
|
||||||
|
}
|
||||||
|
|
||||||
return std::string(
|
return std::string(
|
||||||
buffer.begin(),
|
buffer.begin(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user