writing 身份导入导出

This commit is contained in:
free will
2021-08-05 16:34:12 +08:00
parent 318b565aa6
commit fada6a8a25
3 changed files with 52 additions and 1 deletions
@@ -0,0 +1,41 @@
package examples;
/*
* @Author: Wang Feng
* @Description: 测试身份的导入导出
* @Version: 1.0.0
* @Date: 15:32 2021/8/5
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class IdentityDumpExample {
// 身份信息保存位置
public static String identityPath="D:\\TEST\\NewIdent\\";
// 用户名
public static String username="UserName1";
// 身份文件保存位置
public static String identityFilePath=identityPath+username+".export";
/**
* 生成本地密钥,持久化存储到本地硬盘
* @param username
* @param identityPath
*/
public void generateForeverIdentity(String username,String identityPath){
// identityName是将username前面加上"/"
String identityName="/"+username;
KeyManagerExample.INSTANCE.initKeyChain(identityName,identityPath);
}
public static void main(String[] args){
// 生成数据库身份
new IdentityDumpExample().generateForeverIdentity(username,identityPath);
// 导出数据库身份
try {
KeyManagerExample.INSTANCE.getKeyChain().exportSafeBag("");
} catch (Exception e) {
e.printStackTrace();
}
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ public class CommandExecutor {
// @Description:
// 1. 默认TTL为1,表示当前管理命令只能传递给一跳路由器,即只能做本地管理用
// 2. 如果想通过控制管理命令做远程管理,需要显示设置这个值,将其设置为一个较大值,这样才能将命令兴趣包转发到多跳路由器上
public static final int defaultTTL=1;
public static final int defaultTTL=64;
// 要执行的命令
public IControlCommand command;
+10
View File
@@ -325,6 +325,16 @@ public class KeyChain {
return safeBag;
}
/**
* 默认导出当前身份
* @param passwd
* @return
* @throws Exception
*/
public SafeBag exportSafeBag(String passwd) throws Exception {
return exportSafeBag(this.getCurrentIdentity(),passwd);
}
/**
* 从一个 SafeBag 中导入网络身份,保存到本地
* @param safeBag