Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > blowfish decryption

Reply
Thread Tools

blowfish decryption

 
 
d-fan
Guest
Posts: n/a
 
      05-23-2008
I am including a sample of the "C" coding that I am using to decode a
file. The file was encrypted with a component name Cryptocx in the
windows platform. I need to be able to decrypt the file and poarse
the resulting string into my program. I am using Openssl version
0.9.6. The windows component states that it is using a 448 Bit
keysize and that it automatically base64 encodes the resulting output.

for my information, does the 448 bit key size mean that the key is 14
chars long?

Does anybody see anything wrong with this code? When i try to execute
it I get garbage to the screen as output.

#include <stdlib.h>
#include <string.h>
#include <openssl/blowfish.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/buffer.h>

/* BIO_METHOD * BIO_f_base64(void); */


void decrypt(char *inbuf, char *outbuf, int blklen, char *key)
{
int counter = 0;
char iv[8];
BF_KEY keyStruct;

memset(iv, 0, ;
BF_set_key(&keyStruct, strlen(key), key);
BF_cfb64_encrypt(inbuf, outbuf, blklen, &keyStruct,
iv, &counter, BF_DECRYPT);
}

void encrypt(char *inbuf, char *outbuf, int blklen, char *key)
{
int counter = 0;
char iv[8];
BF_KEY keyStruct;

memset(iv, 0, ;
BF_set_key(&keyStruct, strlen(key), key);
BF_cfb64_encrypt(inbuf, outbuf, blklen, &keyStruct,
iv, &counter, BF_ENCRYPT);
}

void readfile( char * buf ) {
FILE * inf ;
inf = fopen( "locale.txt", "rb" ) ;
printf( "\n\r before read of file \n\r" ) ;

fread(buf, sizeof(buf), 1024, inf) ;
printf( "\n\r after read of file \n\r" ) ;

fclose( inf ) ;
}

void decodebio( unsigned char *encbuf, unsigned char * decbuf, int
destbuf ) {


/* Read Base64 encoded data from standard input and write the
decoded data to standard output: */

BIO *b64, *bio ;
long i ;
char buffer[512] ;
memset(decbuf, 0, 1024) ;

b64 = BIO_new(BIO_f_base64() ) ;
bio = BIO_new(BIO_s_mem()) ;
bio = BIO_push(b64, bio) ;

i=BIO_write(bio, encbuf, strlen(encbuf)) ;
printf( "enc bio i = %d data is %s\n\r", i, encbuf) ;
//i = BIO_ctrl_pending(bio);
i = BIO_read(bio, decbuf, 1024) ;

printf( "the old buffer size is %d %d %s\n\r", i, strlen(decbuf),
decbuf) ;

BIO_set_mem_eof_return(bio,0) ;
BIO_free_all(bio) ;
//printf( "the resulting data is Length %d size %d text %s \n\r" ,
strlen(decbuf), sizeof(decbuf), decbuf) ;
}
int main(int argc, char **argv)
{
char *plain ;
unsigned char filebuf[1024] ;
unsigned char decodebuf[1024] ;
unsigned char *res ;
char *enc;
char *dec;
int len;

char *key1 = "The Password\0" ;
char *key2 = "The Password\0" ;


memset(filebuf, 0, 1024) ;
memset(decodebuf, 0, 1024) ;
readfile( filebuf );

//strcat( filebuf, "\0") ;
printf( "after reading file size %d %s\n\r", strlen(filebuf),
filebuf ) ;
printf( "before decoding file size %d %s\n\r", sizeof(decodebuf),
decodebuf ) ;
decodebio( filebuf, decodebuf, sizeof(decodebuf) ) ;

len = strlen( decodebuf ) ;

enc = malloc(len+1);
enc[len] = '\0';
dec = malloc(len+1);
dec[len] = '\0';

decrypt(decodebuf, dec, len, key2);

printf("key1: '%s'\n", key1);
printf("ley2: '%s'\n", key2);

printf("decrypted: '%s'\n", dec);


}

This is the data from the file. You mighe be able to make use of it.

+i:9f7 x8ƏHWtU'?-u Z,*;K>#id)*Uŷ
I#J*0T)a3|$hO
Gp[0A
A%E9X*M\ AM̚|j=gx.v ӳ
ck?Qvv>vw0x-#jU&\P
QT_?>P ֑^TNk6
 
Reply With Quote
 
 
 
 
Kevin Handy
Guest
Posts: n/a
 
      05-23-2008
d-fan wrote:
> I am including a sample of the "C" coding that I am using to decode a
> file. The file was encrypted with a component name Cryptocx in the
> windows platform. I need to be able to decrypt the file and poarse
> the resulting string into my program. I am using Openssl version
> 0.9.6. The windows component states that it is using a 448 Bit
> keysize and that it automatically base64 encodes the resulting output.
>
> for my information, does the 448 bit key size mean that the key is 14
> chars long?
>
> Does anybody see anything wrong with this code? When i try to execute
> it I get garbage to the screen as output.
>
> #include <stdlib.h>
> #include <string.h>


The following are not part of the C standard, and so
are useless to discuss here. Go to another newsgroup
where they understand this stuff.

> #include <openssl/blowfish.h>
> #include <openssl/bio.h>
> #include <openssl/evp.h>
> #include <openssl/sha.h>
> #include <openssl/hmac.h>
> #include <openssl/buffer.h>
>
> /* BIO_METHOD * BIO_f_base64(void); */
>
>
> void decrypt(char *inbuf, char *outbuf, int blklen, char *key)
> {
> int counter = 0;
> char iv[8];
> BF_KEY keyStruct;
>
> memset(iv, 0, ;
> BF_set_key(&keyStruct, strlen(key), key);
> BF_cfb64_encrypt(inbuf, outbuf, blklen, &keyStruct,
> iv, &counter, BF_DECRYPT);
> }
>
> void encrypt(char *inbuf, char *outbuf, int blklen, char *key)
> {
> int counter = 0;
> char iv[8];
> BF_KEY keyStruct;
>
> memset(iv, 0, ;
> BF_set_key(&keyStruct, strlen(key), key);
> BF_cfb64_encrypt(inbuf, outbuf, blklen, &keyStruct,
> iv, &counter, BF_ENCRYPT);
> }
>
> void readfile( char * buf ) {
> FILE * inf ;
> inf = fopen( "locale.txt", "rb" ) ;
> printf( "\n\r before read of file \n\r" ) ;
>
> fread(buf, sizeof(buf), 1024, inf) ;
> printf( "\n\r after read of file \n\r" ) ;
>
> fclose( inf ) ;
> }
>
> void decodebio( unsigned char *encbuf, unsigned char * decbuf, int
> destbuf ) {
>
>
> /* Read Base64 encoded data from standard input and write the
> decoded data to standard output: */
>
> BIO *b64, *bio ;
> long i ;
> char buffer[512] ;
> memset(decbuf, 0, 1024) ;
>
> b64 = BIO_new(BIO_f_base64() ) ;
> bio = BIO_new(BIO_s_mem()) ;
> bio = BIO_push(b64, bio) ;
>
> i=BIO_write(bio, encbuf, strlen(encbuf)) ;
> printf( "enc bio i = %d data is %s\n\r", i, encbuf) ;
> //i = BIO_ctrl_pending(bio);
> i = BIO_read(bio, decbuf, 1024) ;
>
> printf( "the old buffer size is %d %d %s\n\r", i, strlen(decbuf),
> decbuf) ;
>
> BIO_set_mem_eof_return(bio,0) ;
> BIO_free_all(bio) ;
> //printf( "the resulting data is Length %d size %d text %s \n\r" ,
> strlen(decbuf), sizeof(decbuf), decbuf) ;
> }
> int main(int argc, char **argv)
> {
> char *plain ;
> unsigned char filebuf[1024] ;
> unsigned char decodebuf[1024] ;
> unsigned char *res ;
> char *enc;
> char *dec;
> int len;
>
> char *key1 = "The Password\0" ;
> char *key2 = "The Password\0" ;
>
>
> memset(filebuf, 0, 1024) ;
> memset(decodebuf, 0, 1024) ;
> readfile( filebuf );
>
> //strcat( filebuf, "\0") ;
> printf( "after reading file size %d %s\n\r", strlen(filebuf),
> filebuf ) ;
> printf( "before decoding file size %d %s\n\r", sizeof(decodebuf),
> decodebuf ) ;
> decodebio( filebuf, decodebuf, sizeof(decodebuf) ) ;
>
> len = strlen( decodebuf ) ;
>
> enc = malloc(len+1);
> enc[len] = '\0';
> dec = malloc(len+1);
> dec[len] = '\0';
>
> decrypt(decodebuf, dec, len, key2);
>
> printf("key1: '%s'\n", key1);
> printf("ley2: '%s'\n", key2);
>


> printf("decrypted: '%s'\n", dec);
>
>
> }
>
> This is the data from the file. You mighe be able to make use of it.

[snipped]

It's the notice of a hyperspace bypass being built.

Do you really expect binary data to survive passage
through a text newsgroup? Or that it won't mess up peoples
screens?


----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= - Total Privacy via Encryption =---
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      05-23-2008
d-fan wrote, On 23/05/08 06:15:

<snip>

Someone else pointed out that most of your code is not topical here, but
I did spot some topical problems.

> void readfile( char * buf ) {
> FILE * inf ;
> inf = fopen( "locale.txt", "rb" ) ;


What if fopen fails?

> printf( "\n\r before read of file \n\r" ) ;


Why the \r's?

> fread(buf, sizeof(buf), 1024, inf) ;


sizeof(buf) is the size of a pointer to char, a value that in all
probability is not 1 on your system. You are asking fread to read 1024
objects of that size, yet down below you allocate a buffer of only 1024
chars. 1024*number_greater_than_1 does not fit in 1024!

Also you don't check if fread succeeded. It returns a value for a reason!

> printf( "\n\r after read of file \n\r" ) ;
>
> fclose( inf ) ;
> }


<snip>

> int main(int argc, char **argv)
> {
> char *plain ;
> unsigned char filebuf[1024] ;


<snip>

> readfile( filebuf );


<snip>
--
Flash Gordon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python library for passwd suitable blowfish hash generation Damon Getsman Python 0 06-04-2008 06:53 PM
BlowFish decrypting Claus Wanner C++ 2 11-04-2005 01:19 PM
Blowfish Advanced CS update Stephen Howard Computer Security 0 02-07-2005 11:40 AM
blowfish vs. twofish - help needed BB Computer Security 2 12-23-2004 06:32 PM
Blowfish hash anonymous@coolgroups.com Java 2 05-26-2004 12:04 PM



Advertisments