From 414f2cafc6cf2fe141c011b0d63d447a9b983ac3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 14 Apr 2018 19:45:15 +0200 Subject: Store database storage to files, also loading --- src/LocalUserEncrypted.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/LocalUserEncrypted.cpp (limited to 'src/LocalUserEncrypted.cpp') diff --git a/src/LocalUserEncrypted.cpp b/src/LocalUserEncrypted.cpp new file mode 100644 index 0000000..1c22488 --- /dev/null +++ b/src/LocalUserEncrypted.cpp @@ -0,0 +1,27 @@ +#include "../include/odhtdb/LocalUserEncrypted.hpp" +#include "../include/odhtdb/PasswordHash.hpp" +#include + +namespace odhtdb +{ + EncryptedPrivateKey::EncryptedPrivateKey() + { + memset(nonce, 0, ENCRYPTION_NONCE_BYTE_SIZE); + memset(encryptedPrivateKey, 0, 16 + PRIVATE_KEY_NUM_BYTES); + } + + EncryptedPrivateKey::EncryptedPrivateKey(const EncryptedPrivateKey &other) + { + memcpy(nonce, other.nonce, ENCRYPTION_NONCE_BYTE_SIZE); + memcpy(encryptedPrivateKey, other.encryptedPrivateKey, 16 + PRIVATE_KEY_NUM_BYTES); + } + + Signature::PrivateKey EncryptedPrivateKey::decrypt(const DataView &plainPassword, const DataView &salt) const + { + OwnedMemory hashedPassword = hashPassword(plainPassword, salt); + Decryption decryptedPrivateKey(DataView((void*)encryptedPrivateKey, 16 + PRIVATE_KEY_NUM_BYTES), + DataView((void*)nonce, ENCRYPTION_NONCE_BYTE_SIZE), + DataView(hashedPassword.data, hashedPassword.size)); + return { (const char*)decryptedPrivateKey.getDecryptedText().data, decryptedPrivateKey.getDecryptedText().size }; + } +} -- cgit v1.2.3