提交 a1a82e98 authored 作者: 133's avatar 133

[qukuanbglian] 1

上级 51eab3e4
......@@ -25,7 +25,7 @@ class ApiSignatureUtil {
String str = sb.toString();
String message = str.substring(0, str.length() - 1);
log.info("[SHA256] 参数:{}", map.toString());
return sha256_HMAC(message, key);
return sha256_HMAC(message, key).toUpperCase();
}
......
......@@ -4,10 +4,12 @@ import com.tykj.dev.blockcha.conf.BcUrl;
import com.tykj.dev.blockcha.subject.entity.*;
import com.tykj.dev.blockcha.subject.service.BlockChainUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import sun.applet.Main;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
......@@ -72,15 +74,17 @@ public class BlockChainUtilImpl implements BlockChainUtil {
}
public static void main(String[] args) {
new BlockChainUtilImpl().sendHash(1,"8A4DF5A249BE4B3890EEEA22BD238FEB");
new BlockChainUtilImpl().sendHash(1,"阿斯顿好看");
}
@Override
public BcHash sendHash(Integer subCode, String content) {
SortedMap<Object, Object> request = getRequest();
request.put("content", content);
// content=str2HexStr(content);
request.put("content", HexUtil.hex64(content));
request.put("subCode", subCode);
String s = ApiSignatureUtil.getApiSignature(request, SECRET_KEY).toUpperCase();
String s = ApiSignatureUtil.getApiSignature(request, SECRET_KEY);
request.put("apiSignature", s);
log.info("[block] 生成的Signature是:{}", s);
......
......@@ -169,5 +169,23 @@ public class HexUtil {
}
}
/**
* 哈希上链时,传入content,反64字符16位string
* @param content content
* @return srt
*/
public static String hex64(String content) {
String s = string2HexUTF8(content);
if (s.length() >= 64) {
return s.substring(0, 64);
} else {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 64 - s.length(); i++) {
sb.append(0);
}
return sb.toString() + s;
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论