title: C++ Sha1 issue with using char *
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;openssl/sha.h&gt;
  #include &lt;string.h&gt;
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sstream&gt;
  
  using namespace std;
  
  int main()
  {
  std::stringstream ss;
  
      std::string data;
      data = "hello worl";
      unsigned char digest[SHA_DIGEST_LENGTH];
      char *string1 = strdup(data.c_str());
      // do stuff with string1
      free(string1);
  
      SHA1((unsigned char*)&amp;string1, strlen(string1), (unsigned char*)&amp;digest);    
  
      char mdString[SHA_DIGEST_LENGTH*2+1];
  
      for(int i = 0; i &lt; SHA_DIGEST_LENGTH; i++)
           sprintf(&amp;mdString[i*2], "%02x", (unsigned int)digest[i]);
  
  ss.str("");
  ss &lt;&lt; mdString;
  
   cout &lt;&lt; ss.str() &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>My output always the same..</p>
  
  <pre><code>./sha
  da39a3ee5e6b4b0d3255bfef95601890afd80709
  </code></pre>
  
  <p>Even i change the content of data to "hello panda" or "hello ki" also give me the same output.</p>
  
  <p>Update:
  I took away the free</p>
  
  <pre><code>user1@ubuntu:~/yes/coding$ g++ -o sha sha.cpp -lcrypto
  user1@ubuntu:~/yes/coding$ ./sha
  1bc8b06c5cd4e774195293ea00c959173d8d3789
  user1@ubuntu:~/yes/coding$ ./sha
  c8cf70c522fc564aedb5894a24613542702172ca
  user1@ubuntu:~/yes/coding$ ./sha
  83fbda098c3549ab1347d6cf708ac85092200423
  user1@ubuntu:~/yes/coding$ ./sha
  ea6ccffd78236e22da412ed90a852329f59f8fd5
  user1@ubuntu:~/yes/coding$ ./sha
  0413799befebcb23f5a5c970e48febc7f1aa27fb
  user1@ubuntu:~/yes/coding$ ./sha
  7bd8e7952c78e282b8c117f8c537c456b66207d9
  </code></pre>
  
  <p>The sha change everytime, even i did not change the content of data</p>