Btw, it might help to let us know what's failing (runtime error, unexpected values?). On 8/22/10, Dave <davidct1209@xxxxxxxxx> wrote: > Easy way to find out; does std::string have an overloaded equals > operator and does it perform a copy? You can also try just > constructing a new std::string for the hash and see if that solves the > problem. > > On 8/22/10, Littlefield, Tyler <tyler@xxxxxxxxxxxxx> wrote: >> std::string should strcpy though, no? >> ----- Original Message ----- >> From: "Dave" <davidct1209@xxxxxxxxx> >> To: <programmingblind@xxxxxxxxxxxxx> >> Sent: Sunday, August 22, 2010 5:42 PM >> Subject: Re: generating sha256 hashes with openssl? >> >> >>> From a cursory glance at the function (and without knowing what >>> exactly failed), it potentially looks like you have a dangling >>> pointer. >>> >>> You assign to your password class member an array of characters which >>> you created on the heap (and then delete). >>> >>> On 8/22/10, Littlefield, Tyler <tyler@xxxxxxxxxxxxx> wrote: >>>> Hello all, >>>> I've been trying to figure this out based on documentation from openssl >>>> (what little there is) and some info from google, but it still seems to >>>> be >>>> failing: Any ideas would be great on where I might be going wrong; here >>>> is >>>> the function >>>> void Player::SetPassword(const std::string &s) >>>> { >>>> SHA256_CTX context; >>>> unsigned char *hash = new unsigned char[SHA256_DIGEST_LENGTH+1]; >>>> memset(hash, 0, SHA256_DIGEST_LENGTH+1); >>>> >>>> SHA256_Init(&context); >>>> SHA256_Update(&context, (unsigned char*)s.c_str(), s.length()); >>>> SHA256_Final(hash, &context); >>>> _password=(char*)hash; >>>> delete []hash; >>>> } >>>> Thanks, >>>> Ty >>> __________ >>> View the list's information and change your settings at >>> //www.freelists.org/list/programmingblind >>> >> >> __________ >> View the list's information and change your settings at >> //www.freelists.org/list/programmingblind >> >> > __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind