Android HMAC
ITPOW2017/4/3 21:15:58
以 HmacSHA1 为例:
public class HMACHelper { public static byte[] sha1(String text, String key) { try { byte[] textBytes = text.getBytes("UTF-8"); byte[] keyBytes = key.getBytes("UTF-8"); Mac mac = Mac.getInstance("HmacSHA1"); SecretKey secretKey = new SecretKeySpec(keyBytes, "HmacSHA1"); mac.init(secretKey); return mac.doFinal(textBytes); } catch (Exception e) { e.printStackTrace(); } return new byte[0]; } }
<<返回首页<<