IDEA配置JPBC

目录

1、下载JPBC

2、将解压后的jars文件夹内的jar文件拷贝至项目下新建jars文件夹

3、选中全部的jar文件右键-->加入lib

4、给Library起个名字叫PBC(随便起)

5、将jpbc-2.0.0\params\curves下的a.properties拷贝至项目同级目录 

6、代码测试 

 7、运行结果

参考文献:


1、下载JPBC

官方下载地址https://sourceforge.net/projects/jpbc/files/jpbc_2_0_0/

2、将解压后的jars文件夹内的jar文件拷贝至项目下新建jars文件夹

3、选中全部的jar文件右键-->加入lib

4、给Library起个名字叫PBC(随便起)

5、将jpbc-2.0.0\params\curves下的a.properties拷贝至项目同级目录 

6、代码测试 

 https://blog.csdn.net/dusea/article/details/52335683?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242

参考本篇文章代码进行测试

import it.unisa.dia.gas.jpbc.*;
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory;
import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
interface Ident {

    void buildSystem();

    void extractSecretKey();

    void encrypt();

    void decrypt();

}



/**
 * 时间统计处理机,用于统计各方法耗时
 * @author Administrator
 *
 */
class TimeCountProxyHandle implements InvocationHandler {

    private final Object proxied;

    public TimeCountProxyHandle(Object obj) {
        proxied = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long begin = System.currentTimeMillis();
        Object result = method.invoke(proxied, args);
        long end = System.currentTimeMillis();
        System.out.println(method.getName() + "耗时:" + (end - begin) + "ms");
        return result;
    }
}

class BasicIdent2 implements Ident {

    private Element s, r, P, Ppub, Su, Qu, V, T1, T2;
    private Field G1, Zr;
    private Pairing pairing;

    public BasicIdent2() {
        init();
    }

    /**
     * 初始化
     */
    private void init() {
        pairing = PairingFactory.getPairing("a.properties");//
        PairingFactory.getInstance().setUsePBCWhenPossible(true);
        checkSymmetric(pairing);
        //将变量r初始化为Zr中的元素
        Zr = pairing.getZr();
        r = Zr.newElement();
        //将变量Ppub,Qu,Su,V初始化为G1中的元素,G1是加法群
        G1 = pairing.getG1();
        Ppub = G1.newElement();
        Qu = G1.newElement();
        Su = G1.newElement();
        V = G1.newElement();
        //将变量T1,T2V初始化为GT中的元素,GT是乘法群
        Field GT = pairing.getGT();
        T1 = GT.newElement();
        T2 = GT.newElement();
    }

    /**
     * 判断配对是否为对称配对,不对称则输出错误信息
     *
     */
    private void checkSymmetric(Pairing pairing) {
        if (!pairing.isSymmetric()) {
            throw new RuntimeException("密钥不对称!");
        }
    }

    @Override
    public void buildSystem() {
        System.out.println("-------------------系统建立阶段----------------------");
        s = Zr.newRandomElement().getImmutable();// //随机生成主密钥s
        P = G1.newRandomElement().getImmutable();// 生成G1的生成元P
        Ppub = P.mulZn(s);// 计算Ppub=sP,注意顺序
        System.out.println("P=" + P);
        System.out.println("s=" + s);
        System.out.println("Ppub=" + Ppub);
    }

    @Override
    public void extractSecretKey() {
        System.out.println("-------------------密钥提取阶段----------------------");
        Qu = pairing.getG1().newElement().setFromHash("IDu".getBytes(), 0, 3)
                .getImmutable();// //从长度为3的Hash值IDu确定用户U产生的公钥Qu
        Su = Qu.mulZn(s).getImmutable();
        System.out.println("Qu=" + Qu);
        System.out.println("Su=" + Su);
    }

    @Override
    public void encrypt() {
        System.out.println("-------------------加密阶段----------------------");
        r = Zr.newRandomElement().getImmutable();
        V = P.mulZn(r);
        T1 = pairing.pairing(Ppub, Qu).getImmutable();// 计算e(Ppub,Qu)
        T1 = T1.powZn(r).getImmutable();
        System.out.println("r=" + r);
        System.out.println("V=" + V);
        System.out.println("T1=e(Ppub,Qu)^r=" + T1);
    }

    @Override
    public void decrypt() {
        System.out.println("-------------------解密阶段----------------------");
        T2 = pairing.pairing(V, Su).getImmutable();
        System.out.println("e(V,Su)=" + T2);
        int byt = V.getLengthInBytes();// 求V的字节长度,假设消息长度为128字节
        System.out.println("文本长度" + (byt + 128));
    }

    public static void main(String[] args) {
        BasicIdent2 ident = new BasicIdent2();
        // 动态代理,统计各个方法耗时
        Ident identProxy = (Ident) Proxy.newProxyInstance(
                BasicIdent2.class.getClassLoader(),
                new Class[] { Ident.class }, new TimeCountProxyHandle(ident));

        identProxy.buildSystem();
        identProxy.extractSecretKey();
        identProxy.encrypt();
        identProxy.decrypt();
    }

}

 7、运行结果

至此,程序运行成功即配置成功。

 

参考文献

配置JPBC时参考:https://blog.csdn.net/Lebron_yan/article/details/81538201

代码测试参考: https://blog.csdn.net/dusea/article/details/52335683

 

 

 

  • 8
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
安装IntelliJ IDEA时,可以通过保存Intellij.zip压缩包来保存IDEA配置。具体步骤如下: 1. 执行双击ideaIU-2021.3.2.exe安装程序进行安装。 2. 如果在安装过程中存在MySQL服务,可以在管理员身份下打开cmd命令行,并执行"sc delete mysql"命令来删除MySQL服务。 3. 完成安装后,将Intellij.zip压缩包保存在任意位置,以备将来恢复或导入IDEA配置。 通过保存Intellij.zip压缩包,您可以方便地备份和恢复IDEA配置,包括插件、设置、工程文件等。这样,在重新安装或在其他计算机上使用IntelliJ IDEA时,您可以快速导入之前保存的配置,节省了重新配置的时间和精力。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [idea环境配置.docx](https://download.csdn.net/download/weixin_39563171/85322671)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Java自学视频教程-JavaSE基础-基础加强课-01、JavaSE加强课程介绍,IDEA开发模式统一.mp4](https://download.csdn.net/download/weixin_54787054/88239232)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值