|
@@ -1,6 +1,6 @@
|
|
|
package com.fuzamei.util.blockchain;
|
|
|
|
|
|
-//import gfp2p.Api;
|
|
|
+import smsc.Api;
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.security.InvalidKeyException;
|
|
@@ -76,14 +76,21 @@ public class ProtobufUtils {
|
|
|
}
|
|
|
return protobufBean;
|
|
|
}*/
|
|
|
- /*public static ProtobufBean requestUserCreate(long userUid,String pubkey,String privateKey,String userName) { //用户公钥,调用者的公钥
|
|
|
+ public static ProtobufBean requestUserCreate(long userUid,String adminPubKey) { //用户公钥,调用者的公钥
|
|
|
// String operatorPrivateKey = "90b289fda1fb0439158f837bbe60cc1ec99616dd0bc6335d6fd0bf3d22888e20";
|
|
|
- ProtobufBean protobufBean = new ProtobufBean();
|
|
|
+
|
|
|
+ String platformPrivateKey = "90b289fda1fb0439158f837bbe60cc1ec99616dd0bc6335d6fd0bf3d22888e20"; //平台私钥
|
|
|
+ String pubkey = "b15a4f6c5c1163b5f80715c9bd87d5118ec4b5668cb29f148eeceec61ddeadc2"; //平台公钥
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ProtobufBean protobufBean = new ProtobufBean();
|
|
|
//创建 RequestUserCreate 对象,设置参数
|
|
|
Api.RequestSetAdmin.Builder builder = Api.RequestSetAdmin.newBuilder();
|
|
|
try {
|
|
|
// builder.setUserUid(userUid);
|
|
|
// builder.setUserName(userName);
|
|
|
+ builder.setPubkey(ByteString.copyFrom(HexUtil.hexString2Bytes(adminPubKey)));
|
|
|
SecureRandom secureRandom = new SecureRandom();
|
|
|
long instructionId = secureRandom.nextLong(); //随机数
|
|
|
protobufBean.setInstructionId(instructionId);
|
|
@@ -98,7 +105,7 @@ public class ProtobufUtils {
|
|
|
request.setUid(userUid);
|
|
|
Api.Request request1 = request.build();
|
|
|
// 用操作者的私钥签名
|
|
|
- byte[] bytePrivateKey = HexUtil.hexString2Bytes(privateKey);
|
|
|
+ byte[] bytePrivateKey = HexUtil.hexString2Bytes(platformPrivateKey);
|
|
|
//签名啊
|
|
|
ByteString signByteString = getSign(request1.toByteArray(), bytePrivateKey);
|
|
|
//签名后的结果也给request
|
|
@@ -110,11 +117,11 @@ public class ProtobufUtils {
|
|
|
String signdateBase64 = encodeBase64(requestByte);
|
|
|
protobufBean.setSignature(signdateBase64);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new RuntimeException("生成签名对象出现异常");
|
|
|
}
|
|
|
return protobufBean;
|
|
|
- }*/
|
|
|
- /* private static ByteString getSign(byte[] requestByte, byte[] bytePrivateKey) {
|
|
|
+ }
|
|
|
+ private static ByteString getSign(byte[] requestByte, byte[] bytePrivateKey) {
|
|
|
EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("Ed25519");
|
|
|
byte[] signbyte = new byte[0];
|
|
|
try {
|
|
@@ -132,7 +139,7 @@ public class ProtobufUtils {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return ByteString.copyFrom(signbyte,0,64);
|
|
|
- }*/
|
|
|
+ }
|
|
|
public static String encodeBase64(byte[]input) throws Exception{
|
|
|
Class clazz=Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
|
|
|
Method mainMethod= clazz.getMethod("encode", byte[].class);
|