Re: generating sha256 hashes with openssl?

  • From: Dave <davidct1209@xxxxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 22 Aug 2010 20:02:27 -0700

Yes. I understand that. Just some suggestions for narrowing down the issues.  
Without running it through a debugger, it's hard to diagnose. 

Sent from my iPhone

On Aug 22, 2010, at 6:44 PM, "Littlefield, Tyler" <tyler@xxxxxxxxxxxxx> wrote:

> not deleting will just lead to leaking memory--std::string has to strcpy or 
> memcpy or something after you use '='. And it's def overloaded, otherwise 
> that wouldn't work.
> 
> ----- Original Message ----- From: "Dave" <davidct1209@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Cc: <programmingblind@xxxxxxxxxxxxx>
> Sent: Sunday, August 22, 2010 7:28 PM
> Subject: Re: generating sha256 hashes with openssl?
> 
> 
> Try removing the delete call.
> 
> Sent from my iPhone
> 
> On Aug 22, 2010, at 5:50 PM, "Littlefield, Tyler" <tyler@xxxxxxxxxxxxx> wrote:
> 
>> it's causing a runtime error when I serialize the password into the player's 
>> file.
>> ----- Original Message ----- From: "Dave" <davidct1209@xxxxxxxxx>
>> To: <programmingblind@xxxxxxxxxxxxx>
>> Sent: Sunday, August 22, 2010 6:24 PM
>> Subject: Re: generating sha256 hashes with openssl?
>> 
>> 
>>> 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
>> 
>> __________
>> 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
> 
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: