none
How do I use HMACSHA1 get hash value of a string in windows store app? RRS feed

  • 问题

  • I want write a windows store app,and I want to get the hash value of a string with a my own key,but I don't know how to use HMACSHA1 in windows store app with c#,how to do......?
    2013年5月21日 13:48

答案

  • IBuffer KeyMaterial = CryptographicBuffer.ConvertStringToBinary(consumer_secret + "&" + oauth_token_secret, BinaryStringEncoding.Utf8);
    
                MacAlgorithmProvider HmacSha1Provider = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1");
                CryptographicKey MacKey = HmacSha1Provider.CreateKey(KeyMaterial);
                IBuffer DataToBeSigned = CryptographicBuffer.ConvertStringToBinary(SigBaseString, BinaryStringEncoding.Utf8);
                IBuffer SignatureBuffer = CryptographicEngine.Sign(MacKey, DataToBeSigned);
                String Signature = CryptographicBuffer.EncodeToBase64String(SignatureBuffer);
                string oauth_signature = Uri.EscapeDataString(Signature);

    2013年5月22日 9:03