初始化
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
internal class HmacSHA1Signature : ServiceSignature
|
||||
{
|
||||
private Encoding _encoding = Encoding.UTF8;
|
||||
|
||||
public override string SignatureMethod
|
||||
{
|
||||
get { return "HmacSHA1"; }
|
||||
}
|
||||
|
||||
public override string SignatureVersion
|
||||
{
|
||||
get { return "1"; }
|
||||
}
|
||||
|
||||
public HmacSHA1Signature()
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ComputeSignatureCore(string key, string data)
|
||||
{
|
||||
Debug.Assert(!string.IsNullOrEmpty(data));
|
||||
|
||||
using (KeyedHashAlgorithm algorithm = KeyedHashAlgorithm.Create(
|
||||
this.SignatureMethod.ToString().ToUpperInvariant()))
|
||||
{
|
||||
algorithm.Key = _encoding.GetBytes(key.ToCharArray());
|
||||
return Convert.ToBase64String(
|
||||
algorithm.ComputeHash(_encoding.GetBytes(data.ToCharArray())));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Created by SharpDevelop.
|
||||
* User: xiaoming.yin
|
||||
* Date: 2012/5/30
|
||||
* Time: 14:18
|
||||
*
|
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
*/
|
||||
using System;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of IRequestSigner.
|
||||
/// </summary>
|
||||
internal interface IRequestSigner
|
||||
{
|
||||
/// <summary>
|
||||
/// Signs a request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to sign.</param>
|
||||
/// <param name="credentials">The credentials used to sign.</param>
|
||||
void Sign(ServiceRequest request, ServiceCredentials credentials);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the credentials used to access Aliyun Open Services.
|
||||
/// </summary>
|
||||
internal class ServiceCredentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the access ID.
|
||||
/// </summary>
|
||||
public string AccessId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the access key.
|
||||
/// </summary>
|
||||
public string AccessKey { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize an new instance of <see cref="ServiceCredentials"/>.
|
||||
/// </summary>
|
||||
/// <param name="accessId">The access ID.</param>
|
||||
/// <param name="accessKey">The access key.</param>
|
||||
public ServiceCredentials(string accessId, string accessKey)
|
||||
{
|
||||
if (string.IsNullOrEmpty(accessId))
|
||||
throw new ArgumentException(Aliyun.Api.LOG.Properties.Resources.ExceptionIfArgumentStringIsNullOrEmpty, "accessId");
|
||||
|
||||
AccessId = accessId;
|
||||
AccessKey = accessKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
internal abstract class ServiceSignature
|
||||
{
|
||||
public abstract string SignatureMethod { get; }
|
||||
|
||||
public abstract string SignatureVersion { get; }
|
||||
|
||||
protected ServiceSignature()
|
||||
{
|
||||
}
|
||||
|
||||
public string ComputeSignature(String key, String data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
throw new ArgumentException(Aliyun.Api.LOG.Properties.Resources.ExceptionIfArgumentStringIsNullOrEmpty, "key");
|
||||
if (string.IsNullOrEmpty(data))
|
||||
throw new ArgumentException(Aliyun.Api.LOG.Properties.Resources.ExceptionIfArgumentStringIsNullOrEmpty, "data");
|
||||
|
||||
return ComputeSignatureCore(key, data);
|
||||
}
|
||||
|
||||
protected abstract string ComputeSignatureCore(string key, string data);
|
||||
|
||||
public static ServiceSignature Create()
|
||||
{
|
||||
return new HmacSHA1Signature();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user