mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 09:54:07 +00:00
update JSONTool
This commit is contained in:
parent
8095f9735f
commit
ea7eaf5db4
46
src/main/java/org/bdware/sc/SM2Helper.java
Normal file
46
src/main/java/org/bdware/sc/SM2Helper.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package org.bdware.sc;
|
||||||
|
|
||||||
|
import org.bdware.sc.util.FileUtil;
|
||||||
|
import org.zz.gmhelper.SM2KeyPair;
|
||||||
|
import org.zz.gmhelper.SM2Util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
public class SM2Helper {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
SM2KeyPair pair = SM2Util.generateSM2KeyPair(new SecureRandom());
|
||||||
|
try {
|
||||||
|
if (args.length > 0 && args[0].equals("generateKeyToFile")) {
|
||||||
|
backupFile(new File("./manager.keypair"));
|
||||||
|
backupFile(new File("./manager.key"));
|
||||||
|
System.out.println("Generate file: manger.key, manager.keypair");
|
||||||
|
FileOutputStream fout = new FileOutputStream("./manager.keypair");
|
||||||
|
fout.write(pair.toJson().getBytes(StandardCharsets.UTF_8));
|
||||||
|
fout.close();
|
||||||
|
fout = new FileOutputStream("./manager.key");
|
||||||
|
fout.write(pair.getPublicKeyStr().getBytes(StandardCharsets.UTF_8));
|
||||||
|
fout.close();
|
||||||
|
} else
|
||||||
|
System.out.println(pair.toJson());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void backupFile(File file) {
|
||||||
|
if (!file.exists()) return;
|
||||||
|
File backup = null;
|
||||||
|
for (int i = 0; i <= 100; i++) {
|
||||||
|
if (i == 100) throw new IllegalArgumentException("failed to backup:" + file.getAbsolutePath());
|
||||||
|
backup = new File(file.getParent(), file.getName() + "." + i);
|
||||||
|
if (!backup.exists())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
FileUtil.copyFile(file, backup);
|
||||||
|
System.out.println("Backup: " + file.getAbsolutePath() + " --> " + backup.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import org.bdware.sc.util.HashUtil;
|
|||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.zz.gmhelper.SM2KeyPair;
|
import org.zz.gmhelper.SM2KeyPair;
|
||||||
import wrp.jdk.nashorn.api.scripting.NashornScriptEngine;
|
import wrp.jdk.nashorn.api.scripting.NashornScriptEngine;
|
||||||
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
import wrp.jdk.nashorn.internal.objects.Global;
|
import wrp.jdk.nashorn.internal.objects.Global;
|
||||||
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
||||||
import wrp.jdk.nashorn.internal.runtime.ScriptFunction;
|
import wrp.jdk.nashorn.internal.runtime.ScriptFunction;
|
||||||
|
@ -75,7 +75,6 @@ public class RocksDBUtil {
|
|||||||
try {
|
try {
|
||||||
return new String(rocksDB.get(key.getBytes()));
|
return new String(rocksDB.get(key.getBytes()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.bdware.sc.engine;
|
|||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
|
import wrp.jdk.nashorn.internal.objects.NativeArray;
|
||||||
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
||||||
import wrp.jdk.nashorn.internal.scripts.JO;
|
import wrp.jdk.nashorn.internal.scripts.JO;
|
||||||
|
|
||||||
@ -31,12 +32,11 @@ public class JSONTool {
|
|||||||
}
|
}
|
||||||
return jo;
|
return jo;
|
||||||
} else if (jsonElement.isJsonArray()) {
|
} else if (jsonElement.isJsonArray()) {
|
||||||
JO jo = new JO(PropertyMap.newMap());
|
NativeArray narray = new NativeArray();
|
||||||
jo.setIsArray();
|
|
||||||
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
||||||
for (int i = 0; i < jsonArray.size(); i++)
|
for (int i = 0; i < jsonArray.size(); i++)
|
||||||
jo.put(i, convertJsonElementToMirror(jsonArray.get(i)), false);
|
NativeArray.push(narray, convertJsonElementToMirror(jsonArray.get(i)));
|
||||||
return jo;
|
return narray;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user