android.util.Base64结尾加\n的问题

测试代码,String data,String key.

SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
            Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
            mac.init(signingKey);
            byte[] rawHmac = mac.doFinal(data.getBytes());
            result = new String(Base64.encode(rawHmac, Base64.DEFAULT));

这样生成的字符串即使不到76个字符,result中结尾也会多一个\n

换成下面的代码即可。

Base64.encode(rawHmac, Base64.NO_WRAP)

 

posted @ 2015-08-04 15:14  带狗狗带  Views(547)  Comments(0Edit  收藏  举报