title: Get SHA1 of Unicode string in Crypto++
body: <p>I study C++ independently and I have one problem, which I can't solve more than week. I hope you can help me.</p>
  
  <p>I need to get a SHA1 digest of a Unicode string (like <code>Привет</code>), but I don't know how to do that.</p>
  
  <p>I tried to do it like this, but it returns a wrong digest!</p>
  
  <p>For <code>wstring('Ы')</code>
  It returns - <code>A469A61DF29A7568A6CC63318EA8741FA1CF2A7</code> <br/>
  I need - <code>8dbe718ab1e0c4d75f7ab50fc9a53ec4f0528373</code></p>
  
  <p>Regards and sorry for my English :).</p>
  
  <p>CryptoPP 5.6.2
  MVC++ 2013</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "cryptopp562\cryptlib.h"
  #include "cryptopp562\sha.h"
  #include "cryptopp562\hex.h"
  
  int main() {
  
      std::wstring string(L"Ы");
      int bs_size = (int)string.length() * sizeof(wchar_t);
  
      byte* bytes_string = new byte[bs_size];
  
      int n = 0; //real bytes count
      for (int i = 0; i &lt; string.length(); i++) {
          wchar_t wcharacter = string[i];
  
          int high_byte = wcharacter &amp; 0xFF00;
  
          high_byte = high_byte &gt;&gt; 8;
  
          int low_byte = wcharacter &amp; 0xFF;
  
          if (high_byte != 0) {
              bytes_string[n++] = (byte)high_byte;
          }
  
          bytes_string[n++] = (byte)low_byte;
      }
  
      CryptoPP::SHA1 sha1;
      std::string hash;
  
      CryptoPP::StringSource ss(bytes_string, n, true,
          new CryptoPP::HashFilter(sha1,
              new CryptoPP::HexEncoder(
                  new CryptoPP::StringSink(hash)
              ) 
          ) 
      );
  
      std::cout &lt;&lt; hash &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>