如何在Android上使用MAC访问验证签名标题?
我正在尝试使用Android上的MAC访问验证来签署http头。 我正在使用位于此处的IETF草案#2:
http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-02(1)
使用草案的例子,变量是:
   MAC key identifier: h480djs93hd8
   MAC key: 489dks293j39
   MAC algorithm: hmac-sha-1
   Timestamp: 1336363200
   Nonce: dj83hs9s
以下是标准化的字符串:
 1336363200n
 dj83hs9sn
 GETn
 /resource/1?b=1&a=2n
 example.comn
 80n
 n
我使用下面的方法来编码mac头文件:
private String calculateMAC(final String macAlgorithm, final String normalizedString, final String keyString) {
    try {
        final SecretKeySpec keySpec = new SecretKeySpec((keyString).getBytes("UTF-8"), macAlgorithm);
        final Mac mac = Mac.getInstance(macAlgorithm);
        mac.init(keySpec);
        return Base64.encodeToString(mac.doFinal(normalizedString.getBytes("UTF-8")), Base64.NO_WRAP);
    } catch (final Exception e) {
        Log.e("Error", e.toString());
        return null;
    }
}
  我bhCQXTVyfj5cmA9uKkPFx1zeOXM=的问题是,草案说产生的MAC是“ bhCQXTVyfj5cmA9uKkPFx1zeOXM= ”。  但无论我试图(不同的编码,差异库等),我总是有“ 6T3zZzy2Emppni6bzL7kdRxUWL4= ”。  为什么?? 
(1)最新的草案(http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-03)没有一个例子。 所以很难跟上。
  我在两个不同的平台(php和C#)上尝试过相同的例子,看起来这个例子是不正确的(毕竟它是一个草稿)。  正确的输出是“ 6T3zZzy2Emppni6bzL7kdRxUWL4= ”。 
其他人也看到了同样的问题
链接地址: http://www.djcxy.com/p/48009.html上一篇: How do you sign a header using MAC Access Authentication on Android?
