Initial commit: PrivateBin API C++ DLL implementation
This commit is contained in:
76
include/crypto.h
Normal file
76
include/crypto.h
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef CRYPTO_H
|
||||
#define CRYPTO_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Crypto {
|
||||
public:
|
||||
/**
|
||||
* Generates a random key of specified length
|
||||
*
|
||||
* @param length The length of the key to generate
|
||||
* @return The generated key
|
||||
*/
|
||||
static std::vector<unsigned char> generate_key(size_t length);
|
||||
|
||||
/**
|
||||
* Encrypts data using AES-GCM
|
||||
*
|
||||
* @param plaintext The data to encrypt
|
||||
* @param key The encryption key
|
||||
* @param iv The initialization vector
|
||||
* @param auth_tag Output parameter for the authentication tag
|
||||
* @return The encrypted data
|
||||
*/
|
||||
static std::vector<unsigned char> encrypt(const std::vector<unsigned char>& plaintext,
|
||||
const std::vector<unsigned char>& key,
|
||||
const std::vector<unsigned char>& iv,
|
||||
std::vector<unsigned char>& auth_tag);
|
||||
|
||||
/**
|
||||
* Decrypts data using AES-GCM
|
||||
*
|
||||
* @param ciphertext The data to decrypt
|
||||
* @param key The decryption key
|
||||
* @param iv The initialization vector
|
||||
* @param auth_tag The authentication tag
|
||||
* @return The decrypted data
|
||||
*/
|
||||
static std::vector<unsigned char> decrypt(const std::vector<unsigned char>& ciphertext,
|
||||
const std::vector<unsigned char>& key,
|
||||
const std::vector<unsigned char>& iv,
|
||||
const std::vector<unsigned char>& auth_tag);
|
||||
|
||||
/**
|
||||
* Derives a key using PBKDF2-HMAC-SHA256
|
||||
*
|
||||
* @param password The password to derive from
|
||||
* @param salt The salt to use
|
||||
* @param iterations The number of iterations
|
||||
* @param key_length The length of the derived key
|
||||
* @return The derived key
|
||||
*/
|
||||
static std::vector<unsigned char> pbkdf2_hmac_sha256(const std::string& password,
|
||||
const std::vector<unsigned char>& salt,
|
||||
int iterations,
|
||||
size_t key_length);
|
||||
|
||||
/**
|
||||
* Compresses data using zlib
|
||||
*
|
||||
* @param data The data to compress
|
||||
* @return The compressed data
|
||||
*/
|
||||
static std::vector<unsigned char> compress(const std::vector<unsigned char>& data);
|
||||
|
||||
/**
|
||||
* Decompresses data using zlib
|
||||
*
|
||||
* @param data The data to decompress
|
||||
* @return The decompressed data
|
||||
*/
|
||||
static std::vector<unsigned char> decompress(const std::vector<unsigned char>& data);
|
||||
};
|
||||
|
||||
#endif // CRYPTO_H
|
||||
Reference in New Issue
Block a user