diff --git a/Password_manager/Password_manager.vcxproj b/Password_manager/Password_manager.vcxproj
index 3662ed7..8107d52 100644
--- a/Password_manager/Password_manager.vcxproj
+++ b/Password_manager/Password_manager.vcxproj
@@ -139,6 +139,7 @@
+
diff --git a/Password_manager/Password_manager.vcxproj.filters b/Password_manager/Password_manager.vcxproj.filters
index 2c16131..35be496 100644
--- a/Password_manager/Password_manager.vcxproj.filters
+++ b/Password_manager/Password_manager.vcxproj.filters
@@ -35,5 +35,8 @@
Header Files
+
+ Header Files
+
\ No newline at end of file
diff --git a/Password_manager/include/Buffer.h b/Password_manager/include/Buffer.h
index 26affbe..75fc65b 100644
--- a/Password_manager/include/Buffer.h
+++ b/Password_manager/include/Buffer.h
@@ -5,8 +5,9 @@ class Buffer
{
public:
unsigned char* buffer = nullptr;
- size_t size = 0;
- Buffer(size_t size)
+ int taken = 0;
+ int size = 0;
+ Buffer(int size)
{
this->size = size;
this->buffer = new unsigned char[size];
@@ -22,4 +23,27 @@ public:
if (buffer) delete[] buffer;
}
+ void resize(int new_size)
+ {
+ unsigned char* new_buffer = (unsigned char*)realloc(buffer, new_size);
+ if (!new_buffer)
+ {
+ printf_s("Error resizing buffer\n");
+ return;
+ }
+
+ buffer = new_buffer;
+ size = new_size;
+ }
+
+ void add(void* data, int data_size)
+ {
+ if (taken + data_size > size)
+ {
+ resize(size + data_size);
+ }
+ memcpy_s(buffer + taken, size - taken, data, data_size);
+ taken += data_size;
+ }
+
};
\ No newline at end of file
diff --git a/Password_manager/include/cryptography.h b/Password_manager/include/cryptography.h
index 2eec060..f03ce8f 100644
--- a/Password_manager/include/cryptography.h
+++ b/Password_manager/include/cryptography.h
@@ -1,5 +1,6 @@
#pragma once
#include
+#include "buffer.h"
struct evp_cipher_ctx_st;
typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
@@ -8,16 +9,16 @@ typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
class Cryptography
{
public:
- Cryptography(const char* password);
+ Cryptography(const char* password, size_t size);
~Cryptography();
- int encrypt(uint8_t* input_buffer, int32_t input_buffer_size);
- int decrypt(uint8_t* input_buffer);
-
+ bool encrypt(Buffer* plain, Buffer* encrypted);
+ bool decrypt(Buffer* encrypted, Buffer* decrypted);
+
private:
uint8_t key[32] = { 0 };
uint8_t iv[16] = { 0 };
EVP_CIPHER_CTX* ctx = nullptr;
- bool generate_key_and_iv_from_password(const char* password);
- void handleErrors();
+ bool generate_key_and_iv_from_password(const char* password, size_t size);
+ bool handleErrors();
};
diff --git a/Password_manager/include/func.h b/Password_manager/include/func.h
new file mode 100644
index 0000000..765221f
--- /dev/null
+++ b/Password_manager/include/func.h
@@ -0,0 +1,83 @@
+#pragma once
+#include
+#include "buffer.h"
+
+
+struct Pass
+{
+ char label[20];
+ char password[20];
+
+ Pass()
+ {
+ memset(label, 0, 20);
+ memset(password, 0, 20);
+ };
+};
+
+bool find_password(Buffer* buff, char* label, char* password)
+{
+ Pass* passwords = (Pass*)buff->buffer;
+
+ for (int i = 0; i < buff->taken / sizeof(Pass); i++)
+ {
+ if (!strcmp(passwords[i].label, label))
+ {
+ strcpy_s(password, 20, passwords[i].password);
+ return true;
+ }
+ }
+ return false;
+}
+
+void generate_password(char* password)
+{
+ srand(time(NULL));
+ char characters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_-+={[}]|:;<,>.?";
+ for (int i = 0; i < 15; i++)
+ {
+ password[i] = characters[rand() % (sizeof(characters) - 1)];
+ }
+ password[15] = '\0';
+}
+
+bool save_buffer_to_file(Buffer* buffer)
+{
+ std::ofstream file("passwords.bin", std::ios::binary);
+ if (!file.is_open())
+ {
+ printf_s("Error saving file\n");
+ return false;
+ }
+ file.write((char*)buffer->buffer, buffer->taken);
+ file.close();
+ return true;
+}
+
+bool load_buffer_from_file(Buffer* buffer)
+{
+
+ std::ifstream file("passwords.bin", std::ios::binary);
+ if (!file.is_open()) return false;
+
+ file.seekg(0, std::ios::end);
+ buffer->resize(file.tellg());
+ file.seekg(0, std::ios::beg);
+ file.read((char*)buffer->buffer, buffer->size);
+
+ if (file)
+ buffer->taken = buffer->size;
+ else
+ buffer->taken = file.gcount();
+
+ file.close();
+ return true;
+}
+
+
+void print_usage()
+{
+ printf_s("Usage:\n");
+ printf_s("password_manager.exe