已签名 URL 的 AWS 签名

AWS signature for signed URL

我遇到了一个 .NET 示例,说明如何获取签署 aws 请求 api 调用所需的签名。

我正在开发一个 windows phone 8 应用程序并卡在

KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(algorithm);

看来windows phone8没有Create方法,报错如下:

'System.Security.Cryptography.KeyedHashAlgorithm' does not contain a definition for Create

是否有其他解决方法?

这是完整的代码片段

public static byte[] HmacSHA256(String data, byte[] key)
 {
     String algorithm = "HmacSHA256";
     KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(algorithm);
     kha.Key = key;

     return kha.ComputeHash(Encoding.UTF8.GetBytes(data));
 }



static byte[] getSignatureKey(String key, String dateStamp, String      regionName, String serviceName)
    {
        byte[] kSecret = Encoding.UTF8.GetBytes(("AWS4" + key).ToCharArray());
        byte[] kDate = HmacSHA256(dateStamp, kSecret);
        byte[] kRegion = HmacSHA256(regionName, kDate);
        byte[] kService = HmacSHA256(serviceName, kRegion);
        byte[] kSigning = HmacSHA256("aws4_request", kService);

        return kSigning;
    }

您不需要调用 Create 来创建算法实例,您只需调用 newconstruct 具体 class,例如 new HMACSHA256()

Create 是一种工厂方法,允许您指定要在配置中使用的算法。在台式机和服务器中,同一算法可能有多种实现(本机、硬件加速等),或者您可能希望为用户提供 select 他们想要的算法的选项。

这只是为减少手机和 Silverlight 的运行时大小而从 .NET 中删除的内容之一