못찾은거겠지만 이상하게도 urlencode 함수를 못찾아 결국은 클래스를 추가해 사용하게 되버렸음.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.Storage.Streams;
namespace 0000
{
class utils
{
public static string
CONSUMER_KEY = "CONSUMER_KEY",
CONSUMER_SECRET = "CONSUMER_SECRET";
public static string Md5(string str)
{
var alg = HashAlgorithmProvider.OpenAlgorithm("MD5");
IBuffer buff = CryptographicBuffer.ConvertStringToBinary(str, BinaryStringEncoding.Utf8);
var hashed = alg.HashData(buff);
var res = CryptographicBuffer.EncodeToHexString(hashed);
return res;
}
public static string GetUnixTimeAsString()
{
TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return Convert.ToString(ts.TotalSeconds);
}
public static int GetUnixTimeAsInteger()
{
TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return Convert.ToInt32(ts.TotalSeconds);
}
public static long GetUnixTimeAsLong()
{
TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return Convert.ToInt64(ts.TotalSeconds);
}
public static string HmacSha1(string baseString, string keyString)
{
var crypt = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA1");
var buffer = CryptographicBuffer.ConvertStringToBinary(baseString, BinaryStringEncoding.Utf8);
var keyBuffer = CryptographicBuffer.ConvertStringToBinary(keyString, BinaryStringEncoding.Utf8);
var key = crypt.CreateKey(keyBuffer);
var sigBuffer = CryptographicEngine.Sign(key, buffer);
string signature = CryptographicBuffer.EncodeToBase64String(sigBuffer);
return signature;
}
public static string UrlEncode(string s)
{
switch (s)
{
case "+":
return "%2B";
default:
return System.Uri.EscapeDataString(s);
}
}
}
}
'metro' 카테고리의 다른 글
Windows App Certification Kit Error (0) | 2013.04.27 |
---|
댓글