Hi Berin,Dims,All
Now encoding is working, Thanks for help :).
Now problem is I try to decode the base64 encoded data. But my program
generates runtime error :((.I am using apache xml parser libs to do
that.
I kindly request to every one please help me to solve this issue.
Regards
G J Asanka Priyanjith
My code is
#include <openssl/sha.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <xercesc/util/Base64.hpp>
#include <xercesc/util/XercesDefs.hpp>
#include <iostream>
XERCES_CPP_NAMESPACE_USE
char* doPasswordDigest(unsigned char*,char*,char*);
void hex_print(unsigned char*, int);
void main()
{
doPasswordDigest((unsigned char*)"szxczxcxzz","Y","Y");
}
char* doPasswordDigest(unsigned char *nonce_coded,char *created,char
*passwordin)
{
unsigned char *passwordout = NULL;
int para_size = 0;
char *para_cat= NULL;
char *md_return = NULL;
unsigned int x = 0;
unsigned int *TestI = &x;
unsigned int x2 = 10;
unsigned int *TestII = &x2;
//This one is not working,if I try to run the program It
will //generate runtime error.I just try to print out put and
check.
// std::cout << Base64::decode((const unsigned
//char*)nonce_coded,TestII,0);
//
char *nonce = "";
/*para_cat==nonce + created + password*/
para_size=strlen(nonce)+strlen(created)+strlen(passwordin)+1;
para_cat=(char*)malloc(para_size);
strcpy(para_cat,nonce);
strcat(para_cat,created);
strcat(para_cat,passwordin);
printf("%d\n",TestI);
/*SHA1(para_cat,para_size,passwordwout)==SHA-1 ( nonce + created +
password ) */
passwordout=(unsigned char*)malloc(20);
SHA1((const unsigned char*)para_cat,para_size-1,(unsigned
char*)passwordout);
hex_print(passwordout, 20);
std::cout << Base64::encode(passwordout,20,TestI,0);
/* I want to encode passwordout to Base64*/
free(para_cat);
free(passwordout);
return nonce;/*this is a just a test , after encodeing we have
return base64 encoded hash*/
}
void hex_print(unsigned char *c, int n)
{
int i;
for (i = 0; i < n; i++)
printf("%02x", c[i]);
printf("\n");
}
-----Original Message-----
From: Berin Lautenbach [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 08, 2004 5:45 PM
To: [EMAIL PROTECTED]
Subject: Re: how we can encode SHA-1 hash to Base64
Asanka,
I assume you want to do the encode using OpenSSL?
There is some stuff in the OpenSSL interface for Base64 in xsec that
might provide some pointers.
http://cvs.apache.org/viewcvs.cgi/xml-security/c/src/enc/OpenSSL/OpenSSL
CryptoBase64.cpp?rev=1.7&view=markup
If you want to do it using xsec, there are examples in DSIGReference for
doing it using xsec calls (setHash)
http://cvs.apache.org/viewcvs.cgi/xml-security/c/src/dsig/DSIGReference.
cpp?rev=1.23&view=markup
Cheers,
Berin
Asanka Priyanjitih wrote:
> Hi Team
>
>
>
>
>
> I wrote a piece of code to generate a password digest. But this is not
> complete one. After generating SHA-1 hash, we have to encode SHA-1
hash
> to Base64.If some one knows how can we do that using that libraries or
> some other suitable method please tell me?
>
>
>
> This is that my code
>
>
>
> #include <openssl/sha.h>
>
>
>
> #include <stdio.h>
>
> #include <string.h>
>
> #include <memory.h>
>
> .
>
> .
>
> .
>
> .
>
> .
>
>
>
> char* doPasswordDigest(char *nonce,char *created,char *passwordin)
>
> {
>
> char* passwordout=NULL;
>
> int para_size=0;
>
> char* para_cat=NULL;
>
> char* md_return=NULL;
>
>
>
> /*para_cat==nonce + created + password*/
>
>
>
> para_size=strlen(nonce)+strlen(created)+strlen(passwordin);
>
> para_cat=(char*)malloc(para_size);
>
> strcpy(para_cat,nonce);
>
> strcat(para_cat,created);
>
> strcat(para_cat,passwordin);
>
>
>
>
>
> /*SHA1(para_cat,para_size,passwordwout)==SHA-1 ( nonce + created +
> password ) */
>
>
>
> passwordout = (unsigned char*)malloc(20);
>
> SHA1((const unsigned char*)para_cat,para_size,(unsigned
> char*)passwordout);
>
>
>
> .
>
> .
>
> /* I want to encode passwordout to Base64*/
>
> .
>
> .
>
> .
>
> .
>
>
>
>
>
> free(para_cat);
>
> free(passwordout);
>
>
>
> .
>
> .
>
> }
>
>
>
>
>
>
>
>
>
> Thanks & Regards
>
>
>
>
>
> G J Asanka Priyanjith
>
>
>
>
>
>
>
>
>
>
>
>
------------------------------------------------------------------------
>
------------------------------------------------------------------------
--------------------------
> This message, including any attachments, contains confidential
> information intended for a specific individual and purpose, and is
> intended for the addressee only. Any unauthorized disclosure, use,
> dissemination, copying, or distribution of this message or any of its
> attachments or the information contained in this e-mail, or the taking
> of any action based on it, is strictly prohibited. If you are not the
> intended recipient, please notify the sender immediately by return
> e-mail and delete this message.
>
--------------------------------------------------------------------------------------------------
This message, including any attachments, contains confidential information intended
for a specific individual and purpose, and is intended for the addressee only. Any
unauthorized disclosure, use, dissemination, copying, or distribution of this message
or any of its attachments or the information contained in this e-mail, or the taking
of any action based on it, is strictly prohibited. If you are not the intended
recipient, please notify the sender immediately by return e-mail and delete this
message.