vendredi 6 mars 2020

Trying to encrypt several differant files using AES256 and then decrypt them in a C++ function

so I have a project for a dll file already setup and everything, what I'm trying to do is create a function inside it that basically handles decrypting/encrypting the contents of several files.

I'm currently pushing the file contents into the function as a const char*, file sizes may very per file some being quite small and others larger. the key is also being pushed into the function as a const char* aswell. and to determin if the function should encrypt or decrypt its using an int to determin which mode.

Currently I'm using something called crypto++(https://www.cryptopp.com/) but they don't seem to have good doccumentation thats easily readable so its kinda like stumbling in the dark here.

below is the current function I have, I'm sorta lost on how to go about writing this function to do what I've describbed. I've tried with another library called tiny-aes-c but from what I can tell it would never be able to serve the purpose I need it to.

int mode - should we decrypt or encrypt the string
const char* - the key used for decrypting/encrypting the string
const char* - the string we want to decrypt/encrypt

if the mode is 1, it will store the encrypted const char* in the output variable.
if the mode is 0, it will store the decrypted const char* instead.
const char* Crypt_Wrapper(int mode,const char* key,const char* string){
    // this section is where I'm having the problem, I'm having trouble finding an example thats actually explaining how to go about handling decrypting/encrypting a const char*


    //I'm having trouble also finding the actual function needed for doing the encryption and decryption.
    if(mode == 1){
        output = aes256_encrypt_function();
    }else{
        output = aes256_decrypt_function();
    }
    return output;
}

Aucun commentaire:

Enregistrer un commentaire