D
d-fan
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Ì®:¶±9žf7óÝÆx8†ÆHüW–þƒtU'?-uëí Z, ó;Kì¯ôð>Å#Ûi¹d) ¼UÅ·î
´IÑå#½J*0T)¼aÎ3‚|$hŸ®O
GpÎ[0A¯þ
ƒµ»¤A%µ¨Eº¿9XÜÇM\ï‹óAMµ¬ƒÔÌš¡|jÂí¸=×gx‰¸.áv½ƒõ¯“—©Ó³š
‰ck?¹Q·v·v>vÿò¬w0xâ¯ñã-#–jU&Ê’\²P•
šQT_?ÿý‰¸Á>P¼Ö‘‘^T¹¯€áN‘¸†k6
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Ì®:¶±9žf7óÝÆx8†ÆHüW–þƒtU'?-uëí Z, ó;Kì¯ôð>Å#Ûi¹d) ¼UÅ·î
´IÑå#½J*0T)¼aÎ3‚|$hŸ®O
GpÎ[0A¯þ
ƒµ»¤A%µ¨Eº¿9XÜÇM\ï‹óAMµ¬ƒÔÌš¡|jÂí¸=×gx‰¸.áv½ƒõ¯“—©Ó³š
‰ck?¹Q·v·v>vÿò¬w0xâ¯ñã-#–jU&Ê’\²P•
šQT_?ÿý‰¸Á>P¼Ö‘‘^T¹¯€áN‘¸†k6