...
|
...
|
@@ -46,11 +46,8 @@ import java.util.*; |
|
|
public class ProductChainService {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProductChainService.class);
|
|
|
|
|
|
|
|
|
private String priKeyText;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private ProductInfoMapper productInfoMapper;
|
|
|
|
...
|
...
|
@@ -119,6 +116,8 @@ public class ProductChainService { |
|
|
}
|
|
|
|
|
|
public int updateProductChain(ProductChain chain) {
|
|
|
logger.info("updateProductChain in, chain is {}", chain);
|
|
|
|
|
|
return productChainMapper.updateProductChain(chain);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -158,13 +157,8 @@ public class ProductChainService { |
|
|
|
|
|
// 同步上链的数据
|
|
|
public void addItem(ProductInfoReq bo) {
|
|
|
|
|
|
Long generateid = generateid();
|
|
|
|
|
|
//generateid = 155704809801139L;
|
|
|
|
|
|
logger.info("generateid is : " , generateid);
|
|
|
|
|
|
Long generateid = generateid(); //generateid = 155704809801139L;
|
|
|
logger.info("generateid is : {}" , generateid);
|
|
|
updatechainSql(bo.getTagid(), generateid, null, Integer.valueOf(bo.getTransaction_time()));
|
|
|
|
|
|
try {
|
...
|
...
|
@@ -172,14 +166,14 @@ public class ProductChainService { |
|
|
describe.put("id", generateid);
|
|
|
|
|
|
String sign = generateSign(describe);
|
|
|
logger.info("sign is : " , sign);
|
|
|
logger.info("sign is : {}" , sign);
|
|
|
|
|
|
insertProductInfo(convertVo(bo, generateid, sign));
|
|
|
|
|
|
postChainInfo(describe, generateid, sign);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error("addItem find wrong, bo is " + bo , e);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -245,6 +239,8 @@ public class ProductChainService { |
|
|
String substring = str.substring(0, str.length() - 1);
|
|
|
String hashvalue = RSACoder.getMD5(substring.getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
|
logger.info("generateSign method in, hashvalue is {}, params is {}", hashvalue, params);
|
|
|
|
|
|
// const encodeData = crypto.privateEncrypt(privatekey, Buffer.from(hashvalue)).toString('base64');
|
|
|
String base64Sign = null; //RSA解密
|
|
|
try {
|
...
|
...
|
@@ -299,11 +295,7 @@ public class ProductChainService { |
|
|
|
|
|
public String sign(String plainText) {
|
|
|
try {
|
|
|
if (priKeyText == null) {
|
|
|
// priKeyText = getFileContent();
|
|
|
|
|
|
}
|
|
|
|
|
|
// openssl pkcs8 -topk8 -inform PEM -in private.key -outform pem -nocrypt -out pkcs8.pem
|
|
|
priKeyText = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALFgSglpMKsvXbWa\n" +
|
|
|
"EotTMHWg44nficdZe35C0MioXzHx8s6MnSTDv395LsKrb1YtLUvC5L04CR+Je86G\n" +
|
|
|
"+ysmGyf96sC9K8YfeTlRxW1wSX6YytvdlzHCiUdPbZhZbHEHFDvw7FZvFWHbM1Db\n" +
|
...
|
...
|
@@ -324,100 +316,12 @@ public class ProductChainService { |
|
|
|
|
|
byte[] code1 = encryptByPrivateKey(plainText.getBytes(), priKeyText);
|
|
|
|
|
|
System.out.println("加密后的数据:" + new String(Base64.encodeBase64(code1)));
|
|
|
logger.info("加密后的数据:{}", new String(Base64.encodeBase64(code1)));
|
|
|
return new String(Base64.encodeBase64(code1));
|
|
|
} catch (java.lang.Exception e) {
|
|
|
System.out.println("签名失败");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/* *//**
|
|
|
* 生成32位md5码
|
|
|
*
|
|
|
* @param password
|
|
|
* @return
|
|
|
*//*
|
|
|
public String md5Password(String password) {
|
|
|
try {
|
|
|
MessageDigest digest = MessageDigest.getInstance("md5"); // 得到一个信息摘要器
|
|
|
byte[] result = digest.digest(password.getBytes());
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
for (byte b : result) { // 把每一个byte 做一个与运算 0xff;
|
|
|
int number = b;// 加盐 // 与运算
|
|
|
String str = Integer.toHexString(number);
|
|
|
if (str.length() == 1) {
|
|
|
buffer.append("0");
|
|
|
}
|
|
|
buffer.append(str);
|
|
|
}
|
|
|
return buffer.toString(); // 标准的md5加密后的结果
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
e.printStackTrace();
|
|
|
return "";
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
public byte[] getFileContent() {
|
|
|
byte[] data = (byte[])null;
|
|
|
FileInputStream fis = null;
|
|
|
try {
|
|
|
File f = ResourceUtils.getFile("classpath:rsa_private_key.pem");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//InputStream resourceAsStream = ProductChainService.class.getResourceAsStream("classpath:rsa_private_key.pem");
|
|
|
data = new byte[(int)f.length()];
|
|
|
fis = new FileInputStream(f);
|
|
|
fis.read(data);
|
|
|
fis.close();
|
|
|
} catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
|
|
|
/*public static PrivateKey getPrivateKey() {
|
|
|
PrivateKey priKey = null;
|
|
|
try {
|
|
|
FileInputStream fis = new FileInputStream("rsa_private_key.pem");
|
|
|
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
|
|
char[] pscs = pfxPassword.toCharArray();
|
|
|
keyStore.load(fis, pscs);
|
|
|
priKey = (PrivateKey) (keyStore.getKey(aliasName, pscs));
|
|
|
} catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
return priKey;
|
|
|
}*/
|
|
|
|
|
|
/**
|
|
|
* 字符串Base64解码
|
|
|
*
|
|
|
* @param src 字符串
|
|
|
* @return 经过Base64解码的字符串
|
|
|
*/
|
|
|
public static String base64Decode(String src) {
|
|
|
|
|
|
if (src == null || src.equals("")) {
|
|
|
return null;
|
|
|
logger.error("sign find wrong" + plainText , e);
|
|
|
}
|
|
|
|
|
|
// decodeBase64
|
|
|
|
|
|
org.apache.commons.codec.binary.Base64 decoder = new org.apache.commons.codec.binary.Base64();
|
|
|
byte[] deByte = decoder.decode(src.getBytes(StandardCharsets.UTF_8));
|
|
|
return new String(deByte, StandardCharsets.UTF_8).trim();
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println();
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public void postChainInfoEx(ProductInfo item) {
|
...
|
...
|
@@ -440,7 +344,7 @@ public class ProductChainService { |
|
|
try {
|
|
|
postChainInfo(BeanUtils.describe(build), item.getId(), item.getSign());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error("postChainInfoEx find wrong, item is {}", item);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|