<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Need to use QCryptographicHash and convert an STL function]]></title><description><![CDATA[<p dir="auto">I am totally confused with the changes that need to be done to convert an STL function.</p>
<p dir="auto">I tried the following: <a href="https://stackoverflow.com/a/31012627/1006821" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/a/31012627/1006821</a></p>
<p dir="auto">but the conversion of wstringDevicelocking is just extremely confusing. I have never used STL so the begin and end. I am guessing they are iterators.</p>
<p dir="auto">Any help would be useful, Thanks.</p>
<pre><code>string AuthFile::EncrptedFileName(std::string&amp; userName, std::string&amp; orgName,string&amp; strDeviceLocking)
{ 
  string result;
  string hashVairable = "#" ;
  string hashValue(hashVairable + orgName + hashVairable + "::" + hashVairable + userName + hashVairable);

std::wstring wstringDevicelocking(strDeviceLocking.length(), L' ');
std::copy(strDeviceLocking.begin(), strDeviceLocking.end(), wstringDevicelocking.begin());
wstring guid = L"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
std::string keyaccesStr(hashValue);
wstring keyaccessGuid(keyaccesStr.begin(), keyaccesStr.end());
keyaccessGuid.append(guid);
keyaccessGuid.append(wstringDevicelocking);
string utf8String = wstring_to_utf8(keyaccessGuid);

	 unsigned char digestStr2[SHA_DIGEST_LENGTH];
	 SHA1((unsigned char*)utf8String.c_str(), strlen(utf8String.c_str()), (unsigned char*)&amp;digestStr2);
	 char* utf8StrSha1Base64 = convertToBase64(digestStr2, SHA_DIGEST_LENGTH);
	 string sha1DataStr(utf8StrSha1Base64);

     //Remove all characters except alphabets
     removeForbiddenChar(&amp;sha1DataStr);

     result = sha1DataStr;

	 //printf("\n result [%s] \n", result.c_str());

     return result;
}


void AuthFile::removeForbiddenChar(string *s)
{
    string::iterator it;

    for (it = s-&gt;begin(); it &lt; s-&gt;end(); ++it){
        switch (*it){
        case '/':case '\\':case ':':case '?':case '"':case '&lt;':case '&gt;':case '|':case '=':
            *it = 'B';
        }
    }

}
</code></pre>
]]></description><link>https://forum.qt.io/topic/99925/need-to-use-qcryptographichash-and-convert-an-stl-function</link><generator>RSS for Node</generator><lastBuildDate>Wed, 06 May 2026 17:56:10 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/99925.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Feb 2019 11:49:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Need to use QCryptographicHash and convert an STL function on Wed, 20 Feb 2019 13:54:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> Thank you for that.. I just did a straight up copy.</p>
<p dir="auto">Now just stuck at the last part where the SHA1 and then converting to base64</p>
<pre><code>string utf8String = wstring_to_utf8(keyaccessGuid);

	 unsigned char digestStr2[SHA_DIGEST_LENGTH];
	 SHA1((unsigned char*)utf8String.c_str(), strlen(utf8String.c_str()), (unsigned char*)&amp;digestStr2);
	 char* utf8StrSha1Base64 = convertToBase64(digestStr2, SHA_DIGEST_LENGTH);
	 string sha1DataStr(utf8StrSha1Base64);

     //Remove all characters except alphabets
     removeForbiddenChar(&amp;sha1DataStr);
</code></pre>
<p dir="auto">This is what I am trying to do.</p>
<pre><code>{ ...
QString utf8String = keyaccessGuid.toUtf8();
QByteArray resBytes(utf8String.toStdString().c_str());
QCryptographicHash sha(QCryptographicHash::Sha1);
sha.addData(resBytes);
QByteArray shaBytes = sha.result();
qDebug()&lt;&lt;"Resulting Hash is ";
QString resHash = base64_encode(shaBytes);    
qDebug()&lt;&lt;resHash ;
}

QString base64_encode(QByteArray ba){
    return ba.toBase64();
}

QByteArray base64_decode(QByteArray ba){
    return QByteArray::fromBase64(ba);
}
</code></pre>
<p dir="auto">I am hoping I am on the right track.</p>
]]></description><link>https://forum.qt.io/post/512795</link><guid isPermaLink="true">https://forum.qt.io/post/512795</guid><dc:creator><![CDATA[vivian]]></dc:creator><pubDate>Wed, 20 Feb 2019 13:54:07 GMT</pubDate></item><item><title><![CDATA[Reply to Need to use QCryptographicHash and convert an STL function on Wed, 20 Feb 2019 12:53:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vivian">@<bdi>vivian</bdi></a> said in <a href="/post/512779">Need to use QCryptographicHash and convert an STL function</a>:</p>
<blockquote>
<p dir="auto">I am guessing they are iterators</p>
</blockquote>
<p dir="auto">Yes, they are.</p>
<pre><code>std::copy(strDeviceLocking.begin(), strDeviceLocking.end(), wstringDevicelocking.begin());
</code></pre>
<p dir="auto">copies everything from strDeviceLocking (hence begin and end) to wstringDevicelocking.</p>
]]></description><link>https://forum.qt.io/post/512785</link><guid isPermaLink="true">https://forum.qt.io/post/512785</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 20 Feb 2019 12:53:42 GMT</pubDate></item></channel></rss>