Hi,

>  I am using the below code to do the encytption of the publickey and it
> works fine.
>
> But I need to convert the encrypted format to Binary format inorder to pass
> the encrypted key to a different system.
>

pls suggest how to do the same ??? How can I convert the encrypted message
to binary form ?????????

>
> *Code snippet :*
> **
>
> *void*
> *EncrCardPin(char *pin,char** *encpin)*
>
> *{*
>
> *unsigned char* encrypted = (unsigned char** *) malloc(256);*
>
> **
>
> **
>
> *int** bufSize;*
>
> *char *pubname="publkey.pem"**;*
>
> **
>
> *FILE *keyfile = NULL;*
>
> *RSA* rsa= NULL;*
>
> *FILE *test = NULL;*
>
> *test=fopen(*
> *"test.txt","wb"**);*
>
> **
>
> *printf(**"Opening the puclic key file: [%s]\n"**,pubname);*
>
> *keyfile = fopen(pubname, **"r"**);*
>
> **
>
> *if** (!keyfile)*
>
> *{*
>
> *printf(**"error occured while reading public key file"**);*
>
> **
>
> *}*
>
> *printf(**"Reading the public key block from: [%s] \n"**, pubname);*
>
> *rsa = PEM_read_RSA_PUBKEY(keyfile, NULL, NULL, NULL);*
>
> *if** (rsa == NULL)*
>
> *{*
>
> *printf(**"Badness has occured! Did not read public key file\n"**);*
>
> **
>
> *}*
>
> *else*
>
> *{*
>
> *printf(**"Opened public key file OK!\n"**);*
>
> *}*
>
> *printf(**"Encrypting the message [%s] using public key \n"**,pin);*
>
> *bufSize = RSA_public_encrypt(strlen(pin), (**unsigned char** *) pin,
> encrypted, rsa, RSA_PKCS1_PADDING);*
>
> *if** (bufSize == -1)*
>
> *{*
>
> *printf(**"Badness has occured! encryption failed\n"**);*
>
> *RSA_free(rsa);*
>
> **
>
> *}*
>
> *else*
>
> *{*
>
> *printf(**"Encrypted the message OK! \n"**);*
>
> *//memcpy(encrypted,encpin,1500);*
>
> *sprintf(encpin,**"%s"**,encrypted);*
>
> *fprintf(test,**"%s"**,encpin);*
>
> *RSA_free(rsa);*
>
> *fclose(keyfile);*
>
> *fclose(test);*
>
> **
>
> *}*
>
>
>
>

Reply via email to