remove cryptography class and use aes256 class
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#include "sys.hpp"
|
||||
#include "func.hpp"
|
||||
#include "buffer.hpp"
|
||||
#include "cryptography.hpp"
|
||||
#include "aes256.hpp"
|
||||
|
||||
void print_args()
|
||||
{
|
||||
@@ -104,7 +104,7 @@ std::optional<LoginInfoPointer> arg_get(Buffer &decrypted_buffer, const char *la
|
||||
return get_logininfo_pointer_from_buffer(decrypted_buffer, pass);
|
||||
}
|
||||
|
||||
std::optional<LoginInfoPointer> arg_new_password(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto, bool generate)
|
||||
std::optional<LoginInfoPointer> arg_new_password(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, std::string &key, bool generate)
|
||||
{
|
||||
int pass = find_logininfo_in_buffer(decrypted_buffer, label);
|
||||
std::string username = "";
|
||||
@@ -156,13 +156,13 @@ std::optional<LoginInfoPointer> arg_new_password(Buffer &decrypted_buffer, Buffe
|
||||
}
|
||||
|
||||
add_logininfo_to_buffer(decrypted_buffer, name.c_str(), username.c_str(), password.c_str());
|
||||
crypto.encrypt(decrypted_buffer, encrypted_buffer);
|
||||
Aes256::encrypt(key, decrypted_buffer, encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
Index *index = (Index *)decrypted_buffer.buffer;
|
||||
return get_logininfo_pointer_from_buffer(decrypted_buffer, index->count - 1);
|
||||
}
|
||||
|
||||
void arg_username(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto)
|
||||
void arg_username(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, std::string &key)
|
||||
{
|
||||
int pass = find_logininfo_in_buffer(decrypted_buffer, label);
|
||||
if (pass < 0)
|
||||
@@ -181,11 +181,11 @@ void arg_username(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char
|
||||
|
||||
delete_logininfo_from_buffer(decrypted_buffer, pass);
|
||||
add_logininfo_to_buffer(decrypted_buffer, name.c_str(), username.c_str(), password.c_str());
|
||||
crypto.encrypt(decrypted_buffer, encrypted_buffer);
|
||||
Aes256::encrypt(key, decrypted_buffer, encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
}
|
||||
|
||||
void arg_label_name(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto)
|
||||
void arg_label_name(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, std::string &key)
|
||||
{
|
||||
int pass = find_logininfo_in_buffer(decrypted_buffer, label);
|
||||
|
||||
@@ -205,7 +205,7 @@ void arg_label_name(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const ch
|
||||
|
||||
delete_logininfo_from_buffer(decrypted_buffer, pass);
|
||||
add_logininfo_to_buffer(decrypted_buffer, name.c_str(), username.c_str(), password.c_str());
|
||||
crypto.encrypt(decrypted_buffer, encrypted_buffer);
|
||||
Aes256::encrypt(key, decrypted_buffer, encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ void arg_list(Buffer &decrypted_buffer)
|
||||
}
|
||||
}
|
||||
|
||||
void arg_delete(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label_to_del, Cryptography &crypto)
|
||||
void arg_delete(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label_to_del, std::string &key)
|
||||
{
|
||||
printf("Deleting password for %s\n", label_to_del);
|
||||
int pass = find_logininfo_in_buffer(decrypted_buffer, label_to_del);
|
||||
@@ -241,7 +241,7 @@ void arg_delete(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *
|
||||
|
||||
delete_logininfo_from_buffer(decrypted_buffer, pass);
|
||||
|
||||
crypto.encrypt(decrypted_buffer, encrypted_buffer);
|
||||
Aes256::encrypt(key, decrypted_buffer, encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
printf("Password deleted\n");
|
||||
}
|
||||
@@ -273,7 +273,7 @@ void arg_print_all_p(Buffer &decrypted_buffer, std::string &user_pass)
|
||||
}
|
||||
}
|
||||
|
||||
void arg_change(Buffer &decrypted_buffer, Buffer &encrypted_buffer, std::string &user_pass, Cryptography &crypto)
|
||||
void arg_change(Buffer &decrypted_buffer, Buffer &encrypted_buffer, std::string &user_pass)
|
||||
{
|
||||
printf("Input main password for confirmation:");
|
||||
|
||||
@@ -312,8 +312,7 @@ void arg_change(Buffer &decrypted_buffer, Buffer &encrypted_buffer, std::string
|
||||
return;
|
||||
}
|
||||
|
||||
crypto.change_pass(new_string);
|
||||
crypto.encrypt(decrypted_buffer, encrypted_buffer);
|
||||
Aes256::encrypt(new_string, decrypted_buffer, encrypted_buffer);
|
||||
encrypted_buffer.save_to_file();
|
||||
printf("Password changed\n");
|
||||
}
|
||||
@@ -333,7 +332,7 @@ void arg_show(Buffer &decrypted_buffer, const char *label)
|
||||
}
|
||||
}
|
||||
|
||||
void arg_file(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, Cryptography &crypto, std::string &save_location_path)
|
||||
void arg_file(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, std::string &key, std::string &save_location_path)
|
||||
{
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
@@ -348,7 +347,7 @@ void arg_file(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *la
|
||||
if (decrypted_buffer.taken <= sizeof(Index))
|
||||
return;
|
||||
|
||||
crypto.encrypt(decrypted_buffer, encrypted_buffer);
|
||||
Aes256::encrypt(key, decrypted_buffer, encrypted_buffer);
|
||||
encrypted_buffer.save_to_file(save.string());
|
||||
}
|
||||
|
||||
|
@@ -1,36 +0,0 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
||||
#include "cryptography.hpp"
|
||||
#include "buffer.hpp"
|
||||
#include "aes256.hpp"
|
||||
|
||||
Cryptography::Cryptography(std::string password)
|
||||
{
|
||||
key = password;
|
||||
}
|
||||
|
||||
Cryptography::~Cryptography()
|
||||
{
|
||||
}
|
||||
|
||||
void Cryptography::change_pass(std::string password)
|
||||
{
|
||||
key = password;
|
||||
}
|
||||
|
||||
bool Cryptography::encrypt(Buffer &plain, Buffer &encrypted)
|
||||
{
|
||||
|
||||
Aes256::encrypt(key, plain, encrypted);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Cryptography::decrypt(Buffer &encrypted, Buffer &decrypted)
|
||||
{
|
||||
Aes256::decrypt(key, encrypted, decrypted);
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user