// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package org.apache.commons.codec.digest; import java.io.IOException; import java.io.InputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.StringUtils; // Referenced classes of package org.apache.commons.codec.digest: // HmacAlgorithms public final class HmacUtils { private static final int STREAM_BUFFER_LENGTH = 1024; public HmacUtils() { } public static Mac getHmacMd5(byte abyte0[]) { return getInitializedMac(HmacAlgorithms.HMAC_MD5, abyte0); } public static Mac getHmacSha1(byte abyte0[]) { return getInitializedMac(HmacAlgorithms.HMAC_SHA_1, abyte0); } public static Mac getHmacSha256(byte abyte0[]) { return getInitializedMac(HmacAlgorithms.HMAC_SHA_256, abyte0); } public static Mac getHmacSha384(byte abyte0[]) { return getInitializedMac(HmacAlgorithms.HMAC_SHA_384, abyte0); } public static Mac getHmacSha512(byte abyte0[]) { return getInitializedMac(HmacAlgorithms.HMAC_SHA_512, abyte0); } public static Mac getInitializedMac(String s, byte abyte0[]) { if (abyte0 == null) { throw new IllegalArgumentException("Null key"); } try { abyte0 = new SecretKeySpec(abyte0, s); s = Mac.getInstance(s); s.init(abyte0); } // Misplaced declaration of an exception variable catch (String s) { throw new IllegalArgumentException(s); } // Misplaced declaration of an exception variable catch (String s) { throw new IllegalArgumentException(s); } return s; } public static Mac getInitializedMac(HmacAlgorithms hmacalgorithms, byte abyte0[]) { return getInitializedMac(hmacalgorithms.toString(), abyte0); } public static byte[] hmacMd5(String s, String s1) { return hmacMd5(StringUtils.getBytesUtf8(s), StringUtils.getBytesUtf8(s1)); } public static byte[] hmacMd5(byte abyte0[], InputStream inputstream) throws IOException { return updateHmac(getHmacMd5(abyte0), inputstream).doFinal(); } public static byte[] hmacMd5(byte abyte0[], byte abyte1[]) { try { abyte0 = getHmacMd5(abyte0).doFinal(abyte1); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { throw new IllegalArgumentException(abyte0); } return abyte0; } public static String hmacMd5Hex(String s, String s1) { return Hex.encodeHexString(hmacMd5(s, s1)); } public static String hmacMd5Hex(byte abyte0[], InputStream inputstream) throws IOException { return Hex.encodeHexString(hmacMd5(abyte0, inputstream)); } public static String hmacMd5Hex(byte abyte0[], byte abyte1[]) { return Hex.encodeHexString(hmacMd5(abyte0, abyte1)); } public static byte[] hmacSha1(String s, String s1) { return hmacSha1(StringUtils.getBytesUtf8(s), StringUtils.getBytesUtf8(s1)); } public static byte[] hmacSha1(byte abyte0[], InputStream inputstream) throws IOException { return updateHmac(getHmacSha1(abyte0), inputstream).doFinal(); } public static byte[] hmacSha1(byte abyte0[], byte abyte1[]) { try { abyte0 = getHmacSha1(abyte0).doFinal(abyte1); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { throw new IllegalArgumentException(abyte0); } return abyte0; } public static String hmacSha1Hex(String s, String s1) { return Hex.encodeHexString(hmacSha1(s, s1)); } public static String hmacSha1Hex(byte abyte0[], InputStream inputstream) throws IOException { return Hex.encodeHexString(hmacSha1(abyte0, inputstream)); } public static String hmacSha1Hex(byte abyte0[], byte abyte1[]) { return Hex.encodeHexString(hmacSha1(abyte0, abyte1)); } public static byte[] hmacSha256(String s, String s1) { return hmacSha256(StringUtils.getBytesUtf8(s), StringUtils.getBytesUtf8(s1)); } public static byte[] hmacSha256(byte abyte0[], InputStream inputstream) throws IOException { return updateHmac(getHmacSha256(abyte0), inputstream).doFinal(); } public static byte[] hmacSha256(byte abyte0[], byte abyte1[]) { try { abyte0 = getHmacSha256(abyte0).doFinal(abyte1); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { throw new IllegalArgumentException(abyte0); } return abyte0; } public static String hmacSha256Hex(String s, String s1) { return Hex.encodeHexString(hmacSha256(s, s1)); } public static String hmacSha256Hex(byte abyte0[], InputStream inputstream) throws IOException { return Hex.encodeHexString(hmacSha256(abyte0, inputstream)); } public static String hmacSha256Hex(byte abyte0[], byte abyte1[]) { return Hex.encodeHexString(hmacSha256(abyte0, abyte1)); } public static byte[] hmacSha384(String s, String s1) { return hmacSha384(StringUtils.getBytesUtf8(s), StringUtils.getBytesUtf8(s1)); } public static byte[] hmacSha384(byte abyte0[], InputStream inputstream) throws IOException { return updateHmac(getHmacSha384(abyte0), inputstream).doFinal(); } public static byte[] hmacSha384(byte abyte0[], byte abyte1[]) { try { abyte0 = getHmacSha384(abyte0).doFinal(abyte1); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { throw new IllegalArgumentException(abyte0); } return abyte0; } public static String hmacSha384Hex(String s, String s1) { return Hex.encodeHexString(hmacSha384(s, s1)); } public static String hmacSha384Hex(byte abyte0[], InputStream inputstream) throws IOException { return Hex.encodeHexString(hmacSha384(abyte0, inputstream)); } public static String hmacSha384Hex(byte abyte0[], byte abyte1[]) { return Hex.encodeHexString(hmacSha384(abyte0, abyte1)); } public static byte[] hmacSha512(String s, String s1) { return hmacSha512(StringUtils.getBytesUtf8(s), StringUtils.getBytesUtf8(s1)); } public static byte[] hmacSha512(byte abyte0[], InputStream inputstream) throws IOException { return updateHmac(getHmacSha512(abyte0), inputstream).doFinal(); } public static byte[] hmacSha512(byte abyte0[], byte abyte1[]) { try { abyte0 = getHmacSha512(abyte0).doFinal(abyte1); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { throw new IllegalArgumentException(abyte0); } return abyte0; } public static String hmacSha512Hex(String s, String s1) { return Hex.encodeHexString(hmacSha512(s, s1)); } public static String hmacSha512Hex(byte abyte0[], InputStream inputstream) throws IOException { return Hex.encodeHexString(hmacSha512(abyte0, inputstream)); } public static String hmacSha512Hex(byte abyte0[], byte abyte1[]) { return Hex.encodeHexString(hmacSha512(abyte0, abyte1)); } public static Mac updateHmac(Mac mac, InputStream inputstream) throws IOException { mac.reset(); byte abyte0[] = new byte[1024]; for (int i = inputstream.read(abyte0, 0, 1024); i > -1; i = inputstream.read(abyte0, 0, 1024)) { mac.update(abyte0, 0, i); } return mac; } public static Mac updateHmac(Mac mac, String s) { mac.reset(); mac.update(StringUtils.getBytesUtf8(s)); return mac; } public static Mac updateHmac(Mac mac, byte abyte0[]) { mac.reset(); mac.update(abyte0); return mac; } }