locked
C# to C++

    Question

  • i'm not really familiar with C++ and now need to translate this code to C++. (try to make an app in C++ so et better in it)

    someone can help me with this part:

    public static string CalculateAuthorizationHeader(string username, string domain, string password)
            {
                var credentials = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}:{2}",
                                         domain, username, password);
                Encoding enc = Encoding.GetEncoding("us-ascii");
                return authorizationHeader = "Basic " + Convert.ToBase64String(enc.GetBytes(credentials));
            }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Saturday, December 08, 2012 6:17 PM

Answers

  • thank .. got now this:

    	String^ credentials = domain + "\\" + username + password;
    	auto buffer = CryptographicBuffer::ConvertStringToBinary(credentials, BinaryStringEncoding::Utf8);
    	auto value =  "Basic " + CryptographicBuffer::EncodeToBase64String(buffer);

    and that almost gives the right result.. but few things are diffferent.. i would say its because the encoding is the same but us-ascii was not available. Help?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Jesse Jiang Tuesday, December 25, 2012 8:41 AM
    Saturday, December 15, 2012 2:38 AM

All replies

  • You can use CryptographicBuffer class for encoding.

    Please see API reference for WinRT page at  Security section.


    Sunday, December 09, 2012 3:01 AM
  • thank .. got now this:

    	String^ credentials = domain + "\\" + username + password;
    	auto buffer = CryptographicBuffer::ConvertStringToBinary(credentials, BinaryStringEncoding::Utf8);
    	auto value =  "Basic " + CryptographicBuffer::EncodeToBase64String(buffer);

    and that almost gives the right result.. but few things are diffferent.. i would say its because the encoding is the same but us-ascii was not available. Help?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Marked as answer by Jesse Jiang Tuesday, December 25, 2012 8:41 AM
    Saturday, December 15, 2012 2:38 AM