C Useful


Cryptography



CRC16 And CRC32 Implementations

( https://en.wikipedia.org/wiki/Cyclic_redundancy_check )

Base64 Encode/Decode

( https://en.wikipedia.org/wiki/Base64 )

Get A Positive Random Number Between Number Range

["min" And "max" Values Are Included]
(OpenSSL Library -> libssl Is Required)

( man RAND_poll | man RAND_bytes )

Get A DIRTY Positive Random Number Between Number Range

["min" And "max" Values Are Included]
(This Function Is Very DIRTY, Use Only For Quick Tests)

( man gettimeofday | man srand | man 3 rand )

Generate A Hexadecimal SHA256 Hash From A String [OpenSSL v1.x And v3.x]

(OpenSSL Library -> libssl Is Required)
( man sprintf | man SHA256 )

Generate A Hexadecimal SHA256 Hash From A File [OpenSSL v1.x And v3.x]

(OpenSSL Library -> libssl Is Required)
( man fopen | man sprintf | man SHA256 )

PBKDF2 - Derives A Key From A Password

[With SHA1 or SHA256 or SHA512]
(OpenSSL Library -> libssl Is Required)

( man sprintf | man PKCS5_PBKDF2_HMAC )

Cipher / Decipher Data (AES256 CBC)

[CBC => Cipher Block Chaining]
(OpenSSL Library -> libssl Is Required)

( man EVP_aes_256_cbc )

Cipher / Decipher Data (AES256 GCM)

[GCM => Galois/Counter Mode]
(OpenSSL Library -> libssl Is Required)

( man EVP_aes_256_gcm )

Generate A X509 PEM File [OpenSSL v1.x]

[Certificate + Private Key]
(OpenSSL Library -> libssl Is Required)

( man RSA_generate_key_ex | man X509_new | man PEM_write_X509 )

Generate A X509 PEM File [OpenSSL v3.x]

[Certificate + Private Key]
(OpenSSL Library -> libssl Is Required)

( man EVP_RSA_gen | man X509_new | man PEM_write_X509 )

Sign / Verify Data With Private / Public Keys (X509 Certificate)

(OpenSSL Library -> libcrypto Is Required)
( man PEM_read_PrivateKey | man PEM_read_PUBKEY | man EVP_DigestSignInit | man EVP_DigestVerifyInit )

Verify Client Certificate (X509 Certificate)

[If Signed By CA And Revoked Or Not]
(OpenSSL Library -> libcrypto Is Required)

( man X509_STORE_add_cert | man X509_verify_cert | man X509_CRL_verify | ... )