aboutsummaryrefslogtreecommitdiff
path: root/src/LocalUserEncrypted.cpp
diff options
context:
space:
mode:
authorAleksi Lindeman <0xdec05eba@gmail.com>2018-04-14 19:45:15 +0200
committerAleksi Lindeman <0xdec05eba@gmail.com>2018-04-14 19:45:24 +0200
commit6e4d46f8cf911b82a10e8cd25b65fcc421bbc712 (patch)
tree3d6ee838990389d920df934e20aea1700052ce74 /src/LocalUserEncrypted.cpp
parent9c22be3516d5067b98b06271e2f3545713ff6099 (diff)
Store database storage to files, also loading
Diffstat (limited to 'src/LocalUserEncrypted.cpp')
-rw-r--r--src/LocalUserEncrypted.cpp27
1 files changed, 27 insertions, 0 deletions
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 <cstring>
+
+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 };
+ }
+}