This page contains useful free cryptographic software code that David Ireland has written or adapted in Visual Basic and ANSI C. It's updated frequently, so keep checking.
Ramblings of a Software Engineer, Amusements of a Geek, Cacophony of a Guitarist, An Entropy Admirer's and an Interesting Character's Musings..
Thursday, 27 November 2008
Monday, 9 June 2008
Generating RSA Key Pair Programmatically using OpenSSL
#include "stdafx.h"
#include <conio.h>
#include <openssl/rsa.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <stdlib.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
RSA *myrsa;
unsigned long e = RSA_3;
BIO* out = NULL
FILE* fp;
myrsa = RSA_generate_key(2048,e,NULL,NULL);
out=BIO_new(BIO_s_file());
if(myrsa==NULL){
printf("error in generating keypair..");
printf("press any key to exit..");
_getch();
}
fp=fopen("rsakeypair.txt","wb");
out = BIO_new_fp(fp,BIO_CLOSE);
BIO_printf(out,"\n");
RSA_print(out,myrsa,0);
fclose(fp); _getch(); return(0);
}
The above example program generates a 2048 bit RSA Key pair. It also generates the p,q,n,e and d sections into the text file. In order to build this sample using Visual C++, you will need to build OpenSSL first. After you build OpenSSL, you can then include the generated headers to your VC/Include folder. You will also need to include the the lib files generated by OpenSSL onto VC/Lib. The above example program is written in VS05. OpenSSL simply rocks!
Code + Demo + ReadmeFile : Here
Monday, 2 June 2008
Hashing - Using C# and .Net Framework
A Cryptographic one-way hash function is used to generate a fixed length hash value as a transformation from a specific input. It should be computationally feasible in that it should
- Not have the Avalanche Effect in producing the hash value
- Given h it should be hard to find any m such that h = hash(m)
- It should be collision resistant, i.e given an input m1, It should be hard to find another input, m2 (not equal to m1) such that hash(m1) = hash(m2)
- Resistant to Birthday attacks
.Net Framework BCL provides solid support to some cryptographic hash functions like MD5,SHA1,SHA128,SHA384 and SHA512. I've written a small demo program to compute hash and verify them using the listed cryptographic hash algorithms.
Class Diagram
Output
Sunday, 1 June 2008
System.Security.Cryptography
Complete .Net Cryptography Classes,Interfaces and Enumerations listing from MSDN. Wanted to keep this live on my blog for future references.. Also Check out this article on MSDN [Protecting Private Data with Cryptography Namespaces of the .Net Framework]