1.目录结构
2.导包
将jpbc-api-2.0.0.jar和jpbc-plaf-2.0.0.jar导入到java项目中
网盘链接:链接: https://pan.baidu.com/s/1lFLXQj8v_EhL9KZYaaRv1w?pwd=e8db 提取码: e8db
3.编写代码
a.properties
type a
q 8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791
h 12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776
r 730750818665451621361119245571504901405976559617
exp2 159
exp1 107
sign1 1
sign0 1
BinaryPairing类
import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Field;
import it.unisa.dia.gas.jpbc.Pairing;
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory;
public class BinaryPairing {
public static void main(String[] args) {
Pairing bp = PairingFactory.getPairing("a.properties");
Field Zr = bp.getZr();
Field G1 = bp.getG1();
Field G2 = bp.getG2();
Element g1 = G1.newRandomElement();
Element g2 = G2.newRandomElement();
Element a = Zr.newRandomElement();
Element b = Zr.newRandomElement();
Element g_a = g1.duplicate().powZn(a);
Element g_b = g2.duplicate().powZn(b);
Element egg_ab = bp.pairing(g_a, g_b);
Element egg = bp.pairing(g1, g2);
Element ab = a.duplicate().mul(b);
Element egg_ab_p = egg. duplicate().powZn(ab);
if (egg_ab .isEqual(egg_ab_p))
System.out.println("Yes");
else
System.out.println("No");
}
}