//**************************************************************
#region #### HMAC-SHA256暗号化
//**************************************************************
public string GetHash256( string Base )
{
string HashCode = string.Empty;
using( HMACSHA256 sha256 = new HMACSHA256() )
{
byte[] Buff = Buff = sha256.ComputeHash( Encoding.ASCII.GetBytes( Base ) );
HashCode = Convert.ToBase64String( Buff );
}
return HashCode;
}
#endregion
//**************************************************************
#region #### HMAC-SHA1暗号化
//**************************************************************
public string GetHash( string Key, string Base )
{
string HashCode = string.Empty;
using( HMACSHA1 sha1 = new HMACSHA1( Encoding.UTF8.GetBytes( Key ) ) )
{
byte[] Buff = Buff = sha1.ComputeHash( Encoding.UTF8.GetBytes( Base ) );
HashCode = Convert.ToBase64String( Buff );
}
return HashCode;
}
#endregion
//**************************************************************
#region #### HTTPクエリ変換
//**************************************************************
public string ConvertParamToQuery( Dictionary<string, string> Params )
{
string Query = string.Empty;
foreach( var Param in Params )
{
Query += "&" + HttpUtility.UrlEncode( Param.Key ) + "=" + HttpUtility.UrlEncode( Param.Value );
}
if( 2 < Query.Length ) Query = Query.Substring( 1 );
return Query;
}
#endregion
//**************************************************************
#region #### 署名基本文字列変換
//**************************************************************
public string ConvertParamToSignBase( Dictionary<string, string> Params )
{
string SignBase = string.Empty;
foreach( var Param in Params )
{
SignBase += ", " + HttpUtility.UrlEncode( Param.Key ) + "=\"" + HttpUtility.UrlEncode( Param.Value ) + "\"";
}
if( 2 < SignBase.Length ) SignBase = SignBase.Substring( 2, SignBase.Length - 2 );
return SignBase;
}
#endregion
//**************************************************************
#region #### 32Byteユニークコード生成
//**************************************************************
public string CreateUniqueCode()
{
string UniqueCode = string.Empty;
byte[] Buff = [];
try
{
Buff = Encoding.UTF8.GetBytes( Guid.NewGuid().ToString( "N" ) );
UniqueCode = Convert.ToBase64String( Buff ).Substring( 0, 32 );
}
catch
{
}
return UniqueCode;
}
#endregion
//**************************************************************
#region #### Unixエポック形式時間生成
//**************************************************************
public string CreateUnixEpochTime()
{
TimeSpan ElapsedTime = DateTime.Now.ToUniversalTime() - DateTime.UnixEpoch;
return ((long)ElapsedTime.TotalSeconds).ToString();
}
#endregion