帮助文档优化

This commit is contained in:
egan
2018-01-21 13:29:43 +08:00
parent c5b3fcf27c
commit 76f368b9a9
24 changed files with 104 additions and 174 deletions

View File

@@ -14,8 +14,10 @@ import static com.egzosn.pay.common.http.UriVariables.getMapToParameters;
* 请求实体
*
* @author egan
* @email egzosn@gmail.com
* @date 2017/12/20
* <pre>
* email egzosn@gmail.com
* date 2017/12/20
* </pre>
*/
public class HttpStringEntity extends StringEntity {

View File

@@ -127,7 +127,6 @@ public class UriVariables {
*
* @param str 需要解析的字符串
* @return 解析的结果map
* @throws UnsupportedEncodingException
*/
public static JSONObject getParametersToMap (String str) {

View File

@@ -2,8 +2,7 @@ package com.egzosn.pay.common.util;
import java.math.BigInteger;
public class Util
{
public class Util{
/**
* 整形转换成网络传输的字节流(字节数组)型数据
*
@@ -61,8 +60,8 @@ public class Util
/**
* 大数字转换字节流(字节数组)型数据
*
* @param n
* @return
* @param n 大整形
* @return 字节数组
*/
public static byte[] byteConvert32Bytes(BigInteger n)
{
@@ -96,8 +95,8 @@ public class Util
/**
* 换字节流(字节数组)型数据转大数字
*
* @param b
* @return
* @param b 字节数组
* @return 大整形
*/
public static BigInteger byteConvertInteger(byte[] b)
{
@@ -114,8 +113,8 @@ public class Util
/**
* 根据字节数组获得值(十六进制数字)
*
* @param bytes
* @return
* @param bytes 字节数组
* @return 16进制字符串
*/
public static String getHexString(byte[] bytes)
{
@@ -125,9 +124,9 @@ public class Util
/**
* 根据字节数组获得值(十六进制数字)
*
* @param bytes
* @param upperCase
* @return
* @param bytes 字节数组
* @param upperCase 是否大写
* @return 转换后的字符串
*/
public static String getHexString(byte[] bytes, boolean upperCase)
{
@@ -142,7 +141,7 @@ public class Util
/**
* 打印十六进制字符串
*
* @param bytes
* @param bytes 字节数组
*/
public static void printHexString(byte[] bytes)
{
@@ -187,8 +186,7 @@ public class Util
/**
* Convert char to byte
*
* @param c
* char
* @param c char
* @return byte
*/
public static byte charToByte(char c)
@@ -327,8 +325,7 @@ public class Util
/**
* 数字字符串转ASCII码字符串
*
* @param String
* 字符串
* @param content 字符串
* @return ASCII字符串
*/
public static String StringToAsciiString(String content) {
@@ -389,8 +386,7 @@ public class Util
/**
* 十六转二进制
*
* @param hex
* 十六进制字符串
* @param hex 十六进制字符串
* @return 二进制字符串
*/
public static String hexStringToBinary(String hex) {
@@ -456,8 +452,7 @@ public class Util
/**
* ASCII码字符串转数字字符串
*
* @param String
* ASCII字符串
* @param content ASCII字符串
* @return 字符串
*/
public static String AsciiStringToString(String content) {
@@ -532,8 +527,7 @@ public class Util
/**
* 十进制转换为十六进制字符串
*
* @param algorism
* int 十进制的数字
* @param algorism 十进制的数字
* @return String 对应的十六进制字符串
*/
public static String algorismToHEXString(int algorism) {
@@ -609,7 +603,7 @@ public class Util
/**
* 十六进制串转化为byte数组
*
*@param hex 16进制的字符
* @return the array of byte
*/
public static byte[] hexToByte(String hex)

View File

@@ -27,9 +27,8 @@ import java.util.*;
/**
* @ClassName: CertDescriptor
* @Description: acpsdk证书工具类主要用于对证书的加载和使用
* @date 2016-7-22 下午2:46:20
* acpsdk证书工具类主要用于对证书的加载和使用
* date 2016-7-22 下午2:46:20
* 声明:以下代码只是为了方便接入方测试而提供的样例代码,商户可以根据自己需要,按照技术文档编写。该代码仅供参考,不提供编码,性能,规范性等方面的保障
*/
public class CertDescriptor {
@@ -46,8 +45,8 @@ public class CertDescriptor {
/**
* 通过证书路径初始化为公钥证书
* @param path
* @return
* @param path 证书地址
* @return X509 证书
*/
private static X509Certificate initCert(String path) {
X509Certificate encryptCertTemp = null;
@@ -79,7 +78,7 @@ public class CertDescriptor {
/**
* 通过keyStore 获取私钥签名证书PrivateKey对象
*
* @return
* @return PrivateKey 私钥
*/
public PrivateKey getSignCertPrivateKey(String pwd) {
try {
@@ -133,12 +132,9 @@ public class CertDescriptor {
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param signCertPath
* 证书文件名
* @param signCertPwd
* 证书密码
* @param signCertType
* 证书类型
* @param signCertPath 证书文件名
* @param signCertPwd 证书密码
* @param signCertType 证书类型
*/
public void initPrivateSignCert(String signCertPath, String signCertPwd, String signCertType) {
@@ -158,12 +154,9 @@ public class CertDescriptor {
/**
* 将签名私钥证书文件读取为证书存储对象
*
* @param pfxkeyfile
* 证书文件名
* @param keypwd
* 证书密码
* @param type
* 证书类型
* @param pfxkeyfile 证书文件名
* @param keypwd 证书密码
* @param type 证书类型
* @return 证书对象
* @throws IOException
*/
@@ -208,49 +201,12 @@ public class CertDescriptor {
return null;
}
}
/**
* 使用模和指数生成RSA公钥 注意此代码用了默认补位方式为RSA/None/PKCS1Padding不同JDK默认的补位方式可能不同
*
* @param modulus
* 模
* @param exponent
* 指数
* @return
*/
private PublicKey getPublicKey(String modulus, String exponent) {
try {
BigInteger b1 = new BigInteger(modulus);
BigInteger b2 = new BigInteger(exponent);
KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
RSAPublicKeySpec keySpec = new RSAPublicKeySpec(b1, b2);
return keyFactory.generatePublic(keySpec);
} catch (Exception e) {
log.error("构造RSA公钥失败" + e);
return null;
}
}
/**
* 将字符串转换为X509Certificate对象.
*
* @param x509CertString
* @return
*/
public X509Certificate genCertificateByStr(String x509CertString) {
X509Certificate x509Cert = null;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
InputStream tIn = new ByteArrayInputStream(x509CertString.getBytes("ISO-8859-1"));
x509Cert = (X509Certificate) cf.generateCertificate(tIn);
} catch (Exception e) {
log.error("gen certificate error", e);
}
return x509Cert;
}
/**
* 加载中级证书
* 加载中级证书
* @param certPath 证书地址
*/
public void initPublicCert(String certPath) {
if (!StringUtils.isEmpty(certPath)) {
@@ -260,8 +216,10 @@ public class CertDescriptor {
log.info("PublicKeyCert is empty");
}
}
/**
* 加载根证书
* @param certPath 证书地址
*/
public void initRootCert(String certPath) {
if (!StringUtils.isEmpty(certPath)) {
@@ -274,7 +232,7 @@ public class CertDescriptor {
/**
* 获取公钥/中级证书
* @return
* @return X509Certificate
*/
public X509Certificate getPublicCert() {
return publicKeyCert;
@@ -282,49 +240,16 @@ public class CertDescriptor {
/**
* 获取中级证书
* @return
* @return X509Certificate
*/
public X509Certificate getRootCert() {
return rootKeyCert;
}
/**
* 获取证书的CN
* @param aCert
* @return
*/
private String getIdentitiesFromCertficate(X509Certificate aCert) {
String tDN = aCert.getSubjectDN().toString();
String tPart = "";
if ((tDN != null)) {
String tSplitStr[] = tDN.substring(tDN.indexOf("CN=")).split("@");
if (tSplitStr != null && tSplitStr.length > 2
&& tSplitStr[2] != null)
tPart = tSplitStr[2];
}
return tPart;
}
/**
* 证书文件过滤器
*
*/
static class CerFilter implements FilenameFilter {
public boolean isCer(String name) {
if (name.toLowerCase().endsWith(".cer")) {
return true;
} else {
return false;
}
}
public boolean accept(File dir, String name) {
return isCer(name);
}
}
}

View File

@@ -7,8 +7,11 @@ import org.apache.commons.codec.digest.DigestUtils;
/**
* SHA1签名工具
* @author Actinia
* @email hayesfu@qq.com
* @create 2017 2017/11/27 0027
* <pre>
* email hayesfu@qq.com
*
* create 2017 2017/11/27 0027
* </pre>
*/
public class SHA1 {

View File

@@ -9,8 +9,10 @@ import org.apache.commons.codec.digest.DigestUtils;
/**
* @author Actinia
* @email hayesfu@qq.com
* @create 2017 2017/11/27 0027
* <pre>
* email hayesfu@qq.com
* create 2017 2017/11/27 0027
* </pre>
*/
public class SHA256 {

View File

@@ -219,10 +219,9 @@ public class SM3
/**
* 对最后一个分组字节数据padding
*
* @param in
* @param bLen
* 分组个数
* @return
* @param in 输入字节
* @param bLen 分组个数
* @return 分组好的字节
*/
public static byte[] padding(byte[] in, int bLen)
{
@@ -249,8 +248,8 @@ public class SM3
/**
* 字节数组逆序
*
* @param in
* @return
* @param in 输入字节
* @return 排序好的字节
*/
private static byte[] back(byte[] in)
{

View File

@@ -1,7 +1,6 @@
package com.egzosn.pay.common.util.sign.encrypt.sm3;
public class SM3Digest
{
public class SM3Digest {
/** SM3值的长度 */
private static final int BYTE_LENGTH = 32;
@@ -25,8 +24,8 @@ public class SM3Digest
public SM3Digest() {
}
public SM3Digest(SM3Digest t)
{
public SM3Digest(SM3Digest t){
System.arraycopy(t.xBuf, 0, this.xBuf, 0, t.xBuf.length);
this.xBufOff = t.xBufOff;
System.arraycopy(t.V, 0, this.V, 0, t.V.length);
@@ -37,7 +36,7 @@ public class SM3Digest
*
* @param out 保存SM3结构的缓冲区
* @param outOff 缓冲区偏移量
* @return
* @return 字节长度
*/
public int doFinal(byte[] out, int outOff)
{
@@ -46,6 +45,9 @@ public class SM3Digest
return BYTE_LENGTH;
}
/**
* 重置
*/
public void reset()
{
xBufOff = 0;
@@ -56,12 +58,9 @@ public class SM3Digest
/**
* 明文输入
*
* @param in
* 明文输入缓冲区
* @param inOff
* 缓冲区偏移量
* @param len
* 明文长度
* @param in 明文输入缓冲区
* @param inOff 缓冲区偏移量
* @param len 明文长度
*/
public void update(byte[] in, int inOff, int len)
{
@@ -87,6 +86,9 @@ public class SM3Digest
xBufOff += inputLen;
}
/**
* 更新
*/
private void doUpdate()
{
byte[] B = new byte[BLOCK_LENGTH];
@@ -98,6 +100,10 @@ public class SM3Digest
xBufOff = 0;
}
/**
* 转16进制
* @param B 字节数组
*/
private void doHash(byte[] B)
{
byte[] tmp = SM3.CF(V, B);