Tag: cryptoapi

C#, Programming

RSA 2048 using CryptoAPI and C#

RSACryptoServiceProvider performs asymmetric encryption and decryption using the implementation of the RSA algorithm provided by the cryptographic service provider (CSP). – MSDN Generate Public and Private Keys public static void GenerateKeys(out string PublicKey, out string PrivateKey) { using (RSACryptoServiceProvider RSA2048 = new RSACryptoServiceProvider(2048)) { PublicKey = RSA2048.ToXmlString(false); PrivateKey = RSA2048.ToXmlString(true); } }public static void GenerateKeys(out …

C#, Programming

AES 256 and Base64 using CryptoAPI and C#

Rfc2898DeriveBytes implements password-based key derivation functionality, PBKDF2, by using a pseudo-random number generator based on HMACSHA1. – MSDN Generate salt and key private static string GenerateSaltKey(string password) { Rfc2898DeriveBytes rfc2898db = new Rfc2898DeriveBytes(password, 16, 10000);   byte[] data = new byte[48]; Buffer.BlockCopy(rfc2898db.Salt, 0, data, 0, 16); Buffer.BlockCopy(rfc2898db.GetBytes(32), 0, data, 16, 32); return Convert.ToBase64String(data); }   …

C, Programming

RSA 2048 and Base64 using CryptoAPI and C

RSA is one of the first practical public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key is public and differs from the decryption key which is kept secret. In RSA, this asymmetry is based on the practical difficulty of factoring the product of two large prime numbers, …

C, Programming

AES 256 and Base64 using CryptoAPI and C

The Advanced Encryption Standard (AES), also known as Rijndael (its original name), is a specification for the encryption of electronic data established by the U.S. National Institute of Standards and Technology (NIST) in 2001. AES is based on the Rijndael cipher developed by two Belgian cryptographers, Joan Daemen and Vincent Rijmen, who submitted a proposal …

C, Programming

RC4 and Base64 using CryptoAPI and C

In cryptography, RC4 (Rivest Cipher 4 also known as ARC4 or ARCFOUR meaning Alleged RC4, see below) is a stream cipher. While remarkable for its simplicity and speed in software, multiple vulnerabilities have been discovered in RC4, rendering it insecure. It is especially vulnerable when the beginning of the output keystream is not discarded, or …

C, Programming

Base64 with CryptoAPI and C

CryptBinaryToString The CryptBinaryToString function converts an array of bytes into a formatted string. – MSDN CryptStringToBinary The CryptStringToBinary function converts a formatted string into an array of bytes. – MSDN Base64 Encoding bool Base64EncodeA(char **dest, unsigned long *dlen, const unsigned char *src, unsigned long slen) { if (src == NULL) return false;   if (!CryptBinaryToStringA(src, …

C, Programming

Calculate SHA 512 hash using C and CryptoAPI

SHA-2 (Secure Hash Algorithm 2) is a set of cryptographic hash functions designed by the National Security Agency (NSA).[3] SHA stands for Secure Hash Algorithm. Cryptographic hash functions are mathematical operations run on digital data; by comparing the computed “hash” (the output from execution of the algorithm) to a known and expected hash value, a …