|
@@ -0,0 +1,92 @@
|
|
|
+package cn.efunbox.audio.utils;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+
|
|
|
+public class MD5 {
|
|
|
+ public MD5() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public static final String byte2hexString(byte[] bytes) {
|
|
|
+ StringBuffer buf = new StringBuffer(bytes.length * 2);
|
|
|
+ for (int i = 0; i < bytes.length; i++) {
|
|
|
+ if (((int) bytes[i] & 0xff) < 0x10) {
|
|
|
+ buf.append("0");
|
|
|
+ }
|
|
|
+ buf.append(Long.toString((int) bytes[i] & 0xff, 16));
|
|
|
+ }
|
|
|
+ return buf.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * md5加密
|
|
|
+ * @param sourceString
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String MD5Encode(String sourceString) {
|
|
|
+ String resultString = null;
|
|
|
+ try {
|
|
|
+ resultString = new String(sourceString);
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
+ resultString = byte2hexString(md.digest(resultString.getBytes()));
|
|
|
+ } catch (Exception ex) {
|
|
|
+ }
|
|
|
+ return resultString;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getMD5Str(String str) {
|
|
|
+ MessageDigest messageDigest = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ messageDigest = MessageDigest.getInstance("MD5");
|
|
|
+
|
|
|
+ messageDigest.reset();
|
|
|
+
|
|
|
+ messageDigest.update(str.getBytes("UTF-8"));
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ System.out.println("NoSuchAlgorithmException caught!");
|
|
|
+ System.exit(-1);
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ byte[] byteArray = messageDigest.digest();
|
|
|
+
|
|
|
+ StringBuffer md5StrBuff = new StringBuffer();
|
|
|
+
|
|
|
+ for (int i = 0; i < byteArray.length; i++) {
|
|
|
+ if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
|
|
|
+ md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
|
|
|
+ else
|
|
|
+ md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
|
|
|
+ }
|
|
|
+
|
|
|
+ return md5StrBuff.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws UnsupportedEncodingException {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /* String data = "eyJ0aW1lIjoxNTMwODQ1MTI1LCJtc2dfaWQiOiI2MWJiYzExMTI2NWY0NmM4OTg3OWM2NWQxYmZkZGY1OSIsImVycl9jb2RlIjoiMjAwIiwiZXJyX21zZyI6Ik9LIn0=";
|
|
|
+ String sign = "VB5Ybhu8MBmTMtyzP2J/rMmbmXy87lCkOA7RCDcQE+47IwG+xL5Tx8PYU+1sRBdpK6I65AaYev434fb1+w3kzcMUI0NOjHMnxNGZtDgEMKMQWpoi9njqDpCcXmrO2dDkON0ysF0MN1mD7kg9yz0oFQ4mp3ues/Uk+NzAXU29cbk=";
|
|
|
+
|
|
|
+ String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7BTRi35TsWf8lbsR0z5wpKrHx8CsveKvUk51G2bPlPV9XA9JXcMCGmN6YqihoAwMhXnda4FO78KqBpMja6QqucqQjmbJ+quGc11D7yL1+4+l4CZ8ChPXNvl/R2kZPDQhDg5YiTddL8TBSWSvGbQSTFOfIZZllKKct3InCzBG5HQIDAQAB";
|
|
|
+
|
|
|
+ boolean b = RSASignature.verifySignByPublicKey(data, sign, publicKey, false);
|
|
|
+ System.out.println(b);
|
|
|
+
|
|
|
+ String jsonData = new String(Base64.decodeBase64(data), "utf-8");
|
|
|
+ NotifyResponse msgData = JsonBinder.buildNonNullBinder().fromJson(jsonData, NotifyResponse.class);
|
|
|
+ System.out.println(JSON.toJSONString(msgData));
|
|
|
+
|
|
|
+ String s = JsonBinder.buildNonNullBinder().toJson(msgData);
|
|
|
+ System.out.println(s);*/
|
|
|
+
|
|
|
+ String md5Encode = MD5Encode("123456");
|
|
|
+ System.out.println(md5Encode);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|