<%@Import Namespace="System.Security.Cryptography" %> <img src="http://mqr.kr/qr/?t=HelloWorld&r=10&sign=<%=CalculateSign("t=HelloWorld&r=10", "00112233445566778899aabbccddeeff")%>"/> <script runat="server"> string CalculateSign(string text, string key) { byte[] keyBytes = new byte[key.Length / 2]; for (int i = 0; i < keyBytes.Length; i++) keyBytes[i] = Convert.ToByte(key.Substring(i * 2, 2), 16); byte[] textBytes = Encoding.ASCII.GetBytes(text); byte[] sign; using (HMACSHA256 hmac = new HMACSHA256(keyBytes)) sign = hmac.ComputeHash(textBytes); return string.Join(string.Empty, sign.Select(b => b.ToString("x2"))); } </script>
<%@Import Namespace="System.Security.Cryptography" %> <% string text = DateTime.Now.ToString(@"yyyy\.MM\.dd HH\:mm\:ss"); string query = string.Format("t={0}&r=10&j=1", HttpUtility.HtmlEncode(text)); %> <img src="http://mqr.kr/qr/?<%:query%>&sign=<%:CalculateSign(query, "00112233445566778899aabbccddeeff")%>"/> <script runat="server"> string CalculateSign(string text, string key) { byte[] keyBytes = new byte[key.Length / 2]; for (int i = 0; i < keyBytes.Length; i++) keyBytes[i] = Convert.ToByte(key.Substring(i * 2, 2), 16); byte[] textBytes = Encoding.ASCII.GetBytes(text); byte[] sign; using (HMACSHA256 hmac = new HMACSHA256(keyBytes)) sign = hmac.ComputeHash(textBytes); return string.Join(string.Empty, sign.Select(b => b.ToString("x2"))); } </script>
<%@Import Namespace="System.Security.Cryptography" %> <% string text = Request.Url.ToString(); string query = string.Format("t={0}&r=10&j=1", HttpUtility.HtmlEncode(text)); %> <img src="http://mqr.kr/qr/?<%:query%>&sign=<%:CalculateSign(query, "00112233445566778899aabbccddeeff")%>"/> <script runat="server"> string CalculateSign(string text, string key) { byte[] keyBytes = new byte[key.Length / 2]; for (int i = 0; i < keyBytes.Length; i++) keyBytes[i] = Convert.ToByte(key.Substring(i * 2, 2), 16); byte[] textBytes = Encoding.ASCII.GetBytes(text); byte[] sign; using (HMACSHA256 hmac = new HMACSHA256(keyBytes)) sign = hmac.ComputeHash(textBytes); return string.Join(string.Empty, sign.Select(b => b.ToString("x2"))); } </script>