Tag: openssl

C

Calculate sha256 with OpenSSL and C

To compile the following code you have to link OpenSSL libeay32.lib with your project. To build OpenSSL for Windows please read this post. Includes and Definitions #include <stdlib.h> #include <stdio.h> #include <windows.h> #include <openssl/evp.h>   int HashSHA256(unsigned char *hashed, const unsigned char *plain, size_t plen);#include <stdlib.h> #include <stdio.h> #include <windows.h> #include <openssl/evp.h> int HashSHA256(unsigned char …

PHP

OpenSSL AES 256 CBC encryption in PHP

define(’AES_METHOD’, ‘AES-256-CBC’);   class AES256 { public function Encrypt($password, $plainText) { if(empty($password) || empty($plainText)) { return FALSE; }   //generate a random salt $Salt = openssl_random_pseudo_bytes(8); if($Salt === FALSE){ return FALSE; }   //generate a random initialization vector $IV = openssl_random_pseudo_bytes( openssl_cipher_iv_length( AES_METHOD)); if($IV === FALSE){ return FALSE; }   //generate aes key $pwd = …

C

Base64 with OpenSSL in C

Assuming that you have already built OpenSSL for Windows. Check this guide for details. Link your project with this library from OpenSSL, libeay32.lib. Definitions and Includes: #include <stdlib.h> #include <stdio.h> #include <windows.h> #include <stdbool.h>   #include <openssl/bio.h> #include <openssl/evp.h> #include <openssl/buffer.h>   bool Base64Encode(char **dest, const char *src, unsigned int slen); bool Base64Decode(char **dest, const …