Created
December 9, 2020 14:39
-
-
Save apselon/ae2c0788c431530b45409a7a02c871e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <openssl/evp.h> | |
#include <openssl/sha.h> | |
#include <stdio.h> | |
#include <string.h> | |
enum { MAX_SIZE = 4096 }; | |
enum ErrorCodes {SUCCESS, BAD_ARG }; | |
int main(int argc, char* argv[]) | |
{ | |
if (argc - 1 < 1 ) { | |
return BAD_ARG; | |
} | |
unsigned char data[MAX_SIZE] = ""; | |
int num_read = 0; | |
num_read = fread(data, sizeof(data[0]), MAX_SIZE, stdin); | |
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new(); | |
unsigned char key[32], iv[32]; | |
unsigned char* password = (unsigned char*)argv[1]; | |
size_t pass_len = strlen(argv[1]); | |
EVP_BytesToKey( | |
EVP_aes_256_cbc(), | |
EVP_sha256(), | |
data + 8, | |
password, | |
pass_len, | |
1, | |
key, | |
iv); | |
EVP_DecryptInit(ctx, EVP_aes_256_cbc(), key, iv); | |
unsigned char decrypted[MAX_SIZE] = ""; | |
int p_len = num_read; | |
EVP_DecryptUpdate(ctx, decrypted, &p_len, data, num_read); | |
int num_decrypted = 0; | |
EVP_DecryptFinal(ctx, decrypted + p_len, &num_decrypted); | |
//fwrite(decrypted, sizeof(decrypted[0]), num_decrypted + p_len, stdout); | |
printf("%s", (char*)decrypted); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment