Created
May 31, 2013 20:12
-
-
Save darrelmiller/5687649 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ask the server for a password challenge string | |
var requestId = CryptographicBuffer.EncodeToHexString(CryptographicBuffer.GenerateRandom(4)); | |
var challengeResponse = await _httpClient.GetAsync(_clientBaseUrl + "GetPasswordChallenge?requestId=" + requestId); | |
challengeResponse.EnsureSuccessStatusCode(); | |
var challengeEncoded = await challengeResponse.Content.ReadAsAsync<string>(); | |
var challengeBuffer = CryptographicBuffer.DecodeFromHexString(challengeEncoded); | |
// Use HMAC_SHA512 hash to encode the challenge string using the password being authenticated as the key. | |
var provider = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha512); | |
var passwordBuffer = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8); | |
var hmacKey = provider.CreateKey(passwordBuffer); | |
var buffHmac = CryptographicEngine.Sign(hmacKey, challengeBuffer); | |
var hmacString = CryptographicBuffer.EncodeToHexString(buffHmac); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment