Created
April 22, 2022 12:04
-
-
Save astrokin/36c698ded66707f317412e53994837d4 to your computer and use it in GitHub Desktop.
Decrypt on iOS (CBC, Pkcs7, EVP_BytesToKey) (C part)
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 "EVP_KDF_Salted.h" | |
#include <openssl/evp.h> | |
#include <string.h> | |
int | |
gen_evp_kdf_aes256cbc(const unsigned char *password, const unsigned char *salt, unsigned char key[], unsigned char iv[]) { | |
const EVP_CIPHER *cipher; | |
const EVP_MD *dgst = NULL; | |
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS | OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL); | |
cipher = EVP_get_cipherbyname("aes-256-cbc"); | |
if(!cipher) { fprintf(stderr, "no such cipher\n"); return 1; } | |
dgst=EVP_get_digestbyname("md5"); | |
if(!dgst) { fprintf(stderr, "no such digest\n"); return 1; } | |
int result = EVP_BytesToKey(cipher, dgst, salt, password, strlen(password), 1, key, iv); | |
if (!result) { | |
fprintf(stderr, "EVP_BytesToKey failed\n"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment