Do you know stunnel ( www.stunnel.org ) ? 

You could use that to setup https tunnel.

man evp will give u enuf info on encrypting strings
with OpenSSL. 

OpenSSL really is the definitive resource for
cryptography. :-)

Please find attached my code. It may be of use.

regards,
Girish

--- "Mayorga, Armando CTR NIOC Norfolk N361"
<[EMAIL PROTECTED]> wrote:

> Hello all,
> I'm having a difficulty trying to find API info.
> 
> #1. I need to be able to encrypt strings with AES
> and pass that off to
> other functions that will pass that data over
> regular http.
> 
> #2. For other data I'm looking to setup an https
> tunnel and pass data
> through it.
> 
> I chose to look into OpenSSL so I could kill both of
> these customer
> requirements with one stone and also for ease of
> management and reducing
> code bloat I don't want to have to maintain two
> separate libs in my code
> if one will do both.
> 
> Does anyone have any links to the Crypto API stuff
> or perhaps some
> snippets to share?
> 
> Thanks in advance,
> 
> AJ Mayorga
>
______________________________________________________________________
> OpenSSL Project                                
> http://www.openssl.org
> User Support Mailing List                   
> openssl-users@openssl.org
> Automated List Manager                          
> [EMAIL PROTECTED]
> 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
#include <fcntl.h>
#include <unistd.h>
#include <openssl/evp.h>

#define IV "0xdeadbeefdeadbeef"

int main(int argc, char **argv) {
	EVP_CIPHER_CTX ctx;
	unsigned char key[1024],iv[1024],ibuf[1024],obuf[1024];
	int rfd, wfd,keyfd,ilen,olen,tlen;
	int l = 0;

	if(argc < 3) {
		printf("Usage: %s infile outfile\n",argv[0]);
		exit(128);
	}


	memcpy(iv,IV,sizeof(IV));
	key[0] = 0;

	/* Let us derive a random 256 bit key */
	while(l < 32) {
		char b[128];
		sprintf(b,"%lu",arc4random());
		strcat(key,b);
		l = strlen(key);
	}


 	keyfd =	creat(".key",0644);
	write(keyfd,key,256);
	close(keyfd);

	EVP_CIPHER_CTX_init(&ctx);
	if(!EVP_CipherInit_ex(&ctx, EVP_aes_256_cbc(),NULL,key, iv,1) ) {
	printf("Couldnt initialize cipher\n");
	return 1;
}
/* 1 for encrypt, 0 for decrypt */

	if((rfd = open(argv[1],O_RDONLY) ) == -1) {
		printf("Couldnt open input file\n");
		exit(128);
	}
	if((wfd = creat(argv[2],0644) ) == -1) {
		printf("Couldn't open output file for writing\n");
		exit(128);
	}

	while((ilen = read(rfd,ibuf,1024) ) > 0) {
		if(EVP_CipherUpdate(&ctx,obuf,&olen,ibuf,ilen)){
			write(wfd,obuf,olen);
		}
		else {
			printf("Encryption error\n");
			return 1;
		}

	}
	if(!EVP_CipherFinal_ex(&ctx,obuf+olen,&tlen)) {
		printf("Trouble with padding the last block\n");
		return 1;
	}
	write(wfd,obuf+olen,tlen);
	EVP_CIPHER_CTX_cleanup(&ctx);
	close(rfd);
	close(wfd);

	printf("AES 256 CBC encryption complete\n");
	printf("Secret key is saved to file .key\n");

	return 0;
}
  • Re: String encryption Girish Venkatachalam

Reply via email to