JPBC文件下载
下载地址:JPBC下载
可能受网络影响下载不下来,换个浏览器试一试
下载后解压如下:
将jars文件下的.jar文件全部复制出来:
在项目src同级建立文件夹lib(可以自己命名,后面要添加路径所以要记得),将上述.jar文件粘贴进去,lib文件夹如下图
下载的压缩包里的params/curves里是曲线参数
随便挑一个曲线,一般使用A曲线,将a.properties复制到项目src同级目录下:
pom.xml配置
打开项目pom.xml文件,添加依赖,根据自己需要添加库。systemPath写自己的路径
<dependencies>
<!-- JPBC API -->
<dependency>
<groupId>it.unisa.dia.gas</groupId>
<artifactId>jpbc-api</artifactId>
<version>2.0.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/jpbc-api-2.0.0.jar</systemPath>
</dependency>
<!-- JPBC Cryptography -->
<dependency>
<groupId>it.unisa.dia.gas</groupId>
<artifactId>jpbc-crypto</artifactId>
<version>2.0.0</version>
<systemPath>${pom.basedir}/lib/jpbc-crypto-2.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
<!-- JPBC PBC(基于配对的密码学) -->
<dependency>
<groupId>it.unisa.dia.gas</groupId>
<artifactId>jpbc-pbc</artifactId>
<version>2.0.0</version>
<systemPath>${pom.basedir}/lib/jpbc-pbc-2.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
<!-- JPBC Plaf -->
<dependency>
<groupId>it.unisa.dia.gas</groupId>
<artifactId>jpbc-plaf</artifactId>
<version>2.0.0</version>
<systemPath>${pom.basedir}/lib/jpbc-plaf-2.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
写完后reload一下:
检验是否成功
新建了一个class检验JPBC是哦福成功导入,能运行成功有输出就是成功了
import it.unisa.dia.gas.jpbc.*;
import it.unisa.dia.gas.jpbc.PairingParametersGenerator;
import it.unisa.dia.gas.jpbc.PairingParameters;
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory;
import it.unisa.dia.gas.plaf.jpbc.pairing.a.TypeACurveGenerator;
import java.math.BigInteger;
import java.security.SecureRandom;
public class JPBCTest {
public static void main(String[] args) {
//使用自定义曲线
int rBits = 160; // 素数阶的位长度
int qBits = 512; // 群的位长度
PairingParametersGenerator pg = new TypeACurveGenerator(rBits, qBits);
PairingParameters params = pg.generate();
Pairing pairing = PairingFactory.getPairing(params);
// 获取群G1, G2, GT
Field<Element> G1 = pairing.getG1();
Field<Element> G2 = pairing.getG2();
Field<Element> GT = pairing.getGT();
// 获取生成元
Element P1 = G1.newRandomElement().getImmutable();
Element P2 = G2.newRandomElement().getImmutable();
// 随机选择主私钥
BigInteger N = pairing.getG1().getOrder();
BigInteger ks = new BigInteger(N.bitLength(), new SecureRandom()).mod(N);
BigInteger ke = new BigInteger(N.bitLength(), new SecureRandom()).mod(N);
// 计算主公钥
Element P_pub_s = P2.mul(ks).getImmutable();
Element P_pub_e = P1.mul(ke).getImmutable();
// 输出结果
System.out.println("P_pub_s: " + P_pub_s);
System.out.println("P_pub_e: " + P_pub_e);
}
}