Fixing .gitignore
This commit is contained in:
@@ -1,67 +1,67 @@
|
||||
package com.peanut.common.utils;
|
||||
|
||||
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class KdUtils {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
* str 内容
|
||||
* charset 编码方式
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String MD5(String str, String charset) throws Exception {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(str.getBytes(charset));
|
||||
byte[] result = md.digest();
|
||||
StringBuffer sb = new StringBuffer(32);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
int val = result[i] & 0xff;
|
||||
if (val <= 0xf) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(Integer.toHexString(val));
|
||||
}
|
||||
return sb.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* base64编码
|
||||
* str 内容
|
||||
* charset 编码方式
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static String base64(String str, String charset) throws UnsupportedEncodingException{
|
||||
String encoded = Base64.encode(str.getBytes(charset));
|
||||
return encoded;
|
||||
}
|
||||
|
||||
public static String urlEncoder(String str, String charset) throws UnsupportedEncodingException{
|
||||
String result = URLEncoder.encode(str, charset);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 电商Sign签名生成
|
||||
* content 内容
|
||||
* keyValue ApiKey
|
||||
* charset 编码方式
|
||||
* @throws UnsupportedEncodingException ,Exception
|
||||
* @return DataSign签名
|
||||
*/
|
||||
public static String encrypt (String content, String keyValue, String charset) throws UnsupportedEncodingException, Exception
|
||||
{
|
||||
if (keyValue != null)
|
||||
{
|
||||
return base64(MD5(content + keyValue, charset), charset);
|
||||
}
|
||||
return base64(MD5(content, charset), charset);
|
||||
}
|
||||
|
||||
}
|
||||
package com.peanut.common.utils;
|
||||
|
||||
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class KdUtils {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
* str 内容
|
||||
* charset 编码方式
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String MD5(String str, String charset) throws Exception {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(str.getBytes(charset));
|
||||
byte[] result = md.digest();
|
||||
StringBuffer sb = new StringBuffer(32);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
int val = result[i] & 0xff;
|
||||
if (val <= 0xf) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(Integer.toHexString(val));
|
||||
}
|
||||
return sb.toString().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* base64编码
|
||||
* str 内容
|
||||
* charset 编码方式
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static String base64(String str, String charset) throws UnsupportedEncodingException{
|
||||
String encoded = Base64.encode(str.getBytes(charset));
|
||||
return encoded;
|
||||
}
|
||||
|
||||
public static String urlEncoder(String str, String charset) throws UnsupportedEncodingException{
|
||||
String result = URLEncoder.encode(str, charset);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 电商Sign签名生成
|
||||
* content 内容
|
||||
* keyValue ApiKey
|
||||
* charset 编码方式
|
||||
* @throws UnsupportedEncodingException ,Exception
|
||||
* @return DataSign签名
|
||||
*/
|
||||
public static String encrypt (String content, String keyValue, String charset) throws UnsupportedEncodingException, Exception
|
||||
{
|
||||
if (keyValue != null)
|
||||
{
|
||||
return base64(MD5(content + keyValue, charset), charset);
|
||||
}
|
||||
return base64(MD5(content, charset), charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user