locked
How do I perform a SHA512 hash in C++ WinRT? RRS feed

Answers

  • using namespace Windows::Security::Cryptography; using namespace Windows::Security::Cryptography::Core; using namespace Windows::Storage::Streams; // Convert the message string to binary data. Platform::String ^ hashAlg= HashAlgorithmNames::Sha512; Platform::String ^ strMsg= "mustache";

    IBuffer ^ buffUtf8Msg = CryptographicBuffer::ConvertStringToBinary( strMsg, BinaryStringEncoding::Utf8 ); // Create a HashAlgorithmProvider object. HashAlgorithmProvider ^ objAlgProv = HashAlgorithmProvider::OpenAlgorithm( hashAlg ); // Demonstrate how to retrieve the name of the hashing algorithm. String ^ strAlgNameUsed = objAlgProv->AlgorithmName; // Hash the message. IBuffer ^ buffHash = objAlgProv->HashData(buffUtf8Msg); // Convert the hash to a string (for display). String ^ strHashBase64 = CryptographicBuffer::EncodeToBase64String(buffHash); TextBlockStream->Text += strHashBase64;

    The above is a translation of http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.core.hashalgorithmprovider.aspx#Y205 into C++/CX.

    • Proposed as answer by Andrew7Webb Monday, September 10, 2012 6:57 PM
    • Marked as answer by Andrew Garrison Wednesday, September 12, 2012 4:46 PM
    Monday, September 10, 2012 6:57 PM