假设明文是一个字符串,在执行加密操作之前,我使用setFromHash函数将明文映射到组,并且最终解密只是明文的哈希值,而不是明文,如果不将明文映射到组,我如何解密明文或执行双线性操作?(这可以不使用对称加密实现吗)
setup(pairingParametersFileName, pkFileName, mskFileName);
keygen(pairingParametersFileName, userAttList, pkFileName, mskFileName, skFileName);
String msg = "dasddwhqoiuhdaiosnioacjijdqwi0jdaposdjiasojcbndusivbuiweshfsaoindoai";
//byte[] sha1Result = sha1(msg);
//Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newRandomElement().getImmutable();
//Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newElement().setFromHash(sha1Result, 0, sha1Result.length).getImmutable();
Element message = PairingFactory.getPairing(pairingParametersFileName).getGT().newElement().setFromHash(msg, 0, msg.length).getImmutable();
System.out.println("plaintext:" + msg);
encrypt(pairingParametersFileName, message, accessTree, pkFileName, ctFileName);
Element res = decrypt(pairingParametersFileName, accessTree, ctFileName, skFileName);
System.out.println("decrypt:" + res);
if (message.isEqual(res)) {
System.out.println("successful!");
}
Pairing bp = PairingFactory.getPairing(pairingParametersFileName);
Properties pkProp = loadPropFromFile(pkFileName);
String gString = pkProp.getProperty("g");
Element g = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(gString)).getImmutable();
String g_betaString = pkProp.getProperty("g_beta");
Element g_beta = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(g_betaString)).getImmutable();
String egg_alphaString = pkProp.getProperty("egg_alpha");
Element egg_alpha = bp.getGT().newElementFromBytes(Base64.getDecoder().decode(egg_alphaString)).getImmutable();
Properties ctProp = new Properties();
//compute CT=M *e(g,g)^(alpha s)
Element s = bp.getZr().newRandomElement().getImmutable();
Element CT = message.duplicate().mul(egg_alpha.powZn(s)).getImmutable();
Element C = g_beta.powZn(s).getImmutable();
这是不可实现的,基于配对的CP-ABE,如果加密,需要G_T组中的明文,但是没有好的方法将消息编码到G_T组