忙乎了两天, 终于把项目正确运行起来了.

使用即将发布的Nutz 1.a.32 ,加 JOpenID 1.0.7

地址: http://code.google.com/p/nutzlab/source/browse/#svn/trunk/NutOpenID

同时,发现JOpenID 1.0.7的一个Bug. JOpenID 默认使用UTF-8来对参数进行getBytes. 当参数中还有非英文字符,且没有配置URIEncoding时,获取的byte[]是错误的. 具体代码:

package org.expressme.openid;
//......
public class OpenIdManager {
//......

    String getHmacSha1(String data, byte[] key) {
        SecretKeySpec signingKey = new SecretKeySpec(key, HMAC_SHA1_ALGORITHM);
        Mac mac = null;
        try {
            mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
            mac.init(signingKey);
        }
        catch(NoSuchAlgorithmException e) {
            throw new OpenIdException(e);
        }
        catch(InvalidKeyException e) {
            throw new OpenIdException(e);
        }
        try {
            byte[] rawHmac = mac.doFinal(data.getBytes("UTF-8")); //不一定,也许是ASCII
            return Base64.encodeBytes(rawHmac);
        }
        catch(IllegalStateException e) {
            throw new OpenIdException(e);
        }
        catch(UnsupportedEncodingException e) {
            throw new OpenIdException(e);
        }
    }

//.....
}


blog comments powered by Disqus

Published

2010-10-12 22:16:53

Categories


Tags

Fork me on GitHub