473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

blowfish decryption

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, 8);
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, 8);
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:o
Jun 27 '08 #1
2 6669
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, 8);
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, 8);
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 =---
Jun 27 '08 #2
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
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BKDotCom | last post by:
I'm writing an app that will use blowfish encryption.. PHP's mcrypt will be used if available. if not, I'll use PHPmyadmin's blowfish.php library. The problem is I can't figure out what...
2
by: Hal Vaughan | last post by:
I have no background in encryption, so I'm working with samples I've found in various places and patching them together. I know Blowfish can use a 56 byte key. The version of this program in Perl...
2
by: Claus Wanner | last post by:
Hi NewsGroup, some days ago i've started to coding an decryting function to decyrpt a Passwort. The password is BlowFish encrypted and than Base64 encodet. An other application send the...
0
by: Peter | last post by:
A while back I saw the posting for this blowfish application. I was wondering if anyone knows if this implementation is over 448 bits? http://www.todd.acheson.com/Blowfish.NET.zip
3
by: Iain | last post by:
Hi I need Blowfish encyption (freeware hopefully) for a c# project, any ideas where to start? TIA Iain
1
by: Vipul Kulshrestha | last post by:
Hello Friends, I need to an encryption of passpword and store it in a file. I am looking for a code in C. I m having a code in C for Blowfish encryption but it takes long values as input . But I...
2
by: Derrick | last post by:
Has anyone been able to get blowfish decryption working from C#, in 1.1? I found sourcecode for 2.0, but there is enough 2.0 specific code in there that I'm trying to find a 1.1 library. ...
2
by: Demosthenes | last post by:
Does anyone have a simple implementation of Blowfish encryption ? I have gone to freevbcode.com and it wants me to download two installers that install a "chillkat" framework and so on. I really...
13
by: Tom Andrecht | last post by:
I'm trying to get some encryption/decryption routines going to take care of my data, and while the encryption is working great, I keep running into the message "Padding is invalid and cannot be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.