基于变换生物特征加密
This commit is contained in:
14
BioIBE/.classpath
Normal file
14
BioIBE/.classpath
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="lib/bcprov-jdk16-1.46.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jna-3.2.5.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jpbc-api-2.0.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jpbc-benchmark-2.0.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jpbc-crypto-2.0.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jpbc-mm-2.0.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jpbc-pbc-2.0.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jpbc-plaf-2.0.0.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
BioIBE/.project
Normal file
17
BioIBE/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MyNewBioIBE3</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
11
BioIBE/.settings/org.eclipse.jdt.core.prefs
Normal file
11
BioIBE/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
8
BioIBE/bin/a.properties
Normal file
8
BioIBE/bin/a.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
type a
|
||||
q 1571
|
||||
r 131
|
||||
h 12
|
||||
exp1 1
|
||||
exp2 7
|
||||
sign0 1
|
||||
sign1 1
|
||||
BIN
BioIBE/bin/bioibe/impl/BioGUIImpl.class
Normal file
BIN
BioIBE/bin/bioibe/impl/BioGUIImpl.class
Normal file
Binary file not shown.
BIN
BioIBE/bin/bioibe/impl/BioIBEImpl.class
Normal file
BIN
BioIBE/bin/bioibe/impl/BioIBEImpl.class
Normal file
Binary file not shown.
54
BioIBE/bin/bioibe/impl/alpha.txt
Normal file
54
BioIBE/bin/bioibe/impl/alpha.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
{x=194,y=1107},a
|
||||
{x=535,y=684},b
|
||||
{x=1489,y=1233},c
|
||||
{x=535,y=887},d
|
||||
{x=383,y=415},e
|
||||
{x=102,y=1304},f
|
||||
{x=1226,y=854},g
|
||||
{x=70,y=754},h
|
||||
{x=424,y=1260},i
|
||||
{x=1138,y=993},j
|
||||
{x=384,y=1054},k
|
||||
{x=869,y=1178},l
|
||||
{x=1548,y=760},m
|
||||
{x=626,y=233},n
|
||||
{x=293,y=728},o
|
||||
{x=1534,y=529},p
|
||||
{x=1086,y=1480},q
|
||||
{x=1534,y=1042},r
|
||||
{x=190,y=1385},s
|
||||
{x=1363,y=1371},t
|
||||
{x=297,y=947},u
|
||||
{x=158,y=649},v
|
||||
{x=894,y=654},w
|
||||
{x=879,y=447},x
|
||||
{x=822,y=291},y
|
||||
{x=792,y=997},z
|
||||
{x=1157,y=153},A
|
||||
{x=1299,y=299},B
|
||||
{x=764,y=1043},C
|
||||
{x=259,y=688},D
|
||||
{x=336,y=1296},E
|
||||
{x=1510,y=810},F
|
||||
{x=194,y=464},G
|
||||
{x=987,y=1012},H
|
||||
{x=363,y=14},I
|
||||
{x=535,y=684},J
|
||||
{x=1057,y=398},K
|
||||
{x=1025,y=99},L
|
||||
{x=792,y=574},M
|
||||
{x=605,y=206},N
|
||||
{x=122,y=1508},O
|
||||
{x=1393,y=490},P
|
||||
{x=190,y=186},Q
|
||||
{x=1404,y=632},R
|
||||
{x=1133,y=1467},S
|
||||
{x=1122,y=439},T
|
||||
{x=384,y=517},U
|
||||
{x=64,y=579},V
|
||||
{x=1489,y=338},W
|
||||
{x=1105,y=1505},X
|
||||
{x=1404,y=939},Y
|
||||
{x=184,y=899},Z
|
||||
{x=1299,y=1272},.
|
||||
{x=1157,y=153},,
|
||||
BIN
BioIBE/bin/bioibe/util/BioIBEUtil.class
Normal file
BIN
BioIBE/bin/bioibe/util/BioIBEUtil.class
Normal file
Binary file not shown.
10
BioIBE/bin/biopk.txt
Normal file
10
BioIBE/bin/biopk.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
110 , 121 , 121 , 89 , 118 , 52 , 108 , 115 , 113 , 1
|
||||
3 , 79 , 129 , 77 , 45 , 6 , 103 , 82 , 81 , 1
|
||||
112 , 53 , 0 , 3 , 15 , 2 , 118 , 34 , 118 , 1
|
||||
126 , 56 , 110 , 59 , 99 , 115 , 85 , 42 , 124 , 1
|
||||
16 , 87 , 27 , 95 , 87 , 79 , 16 , 40 , 18 , 1
|
||||
19 , 115 , 97 , 119 , 37 , 57 , 99 , 8 , 58 , 1
|
||||
60 , 82 , 43 , 13 , 106 , 86 , 70 , 10 , 6 , 1
|
||||
34 , 67 , 108 , 4 , 57 , 14 , 61 , 45 , 78 , 1
|
||||
106 , 69 , 70 , 116 , 114 , 108 , 62 , 101 , 42 , 1
|
||||
67 , 96 , 104 , 59 , 24 , 107 , 72 , 75 , 107 , 1
|
||||
10
BioIBE/bin/biosk.txt
Normal file
10
BioIBE/bin/biosk.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
93 , 79 , 36 , 92 , 23 , 114 , 89 , 94 , 20 , 9
|
||||
28 , 96 , 67 , 36 , 47 , 69 , 9 , 57 , 5 , 23
|
||||
102 , 129 , 98 , 96 , 36 , 11 , 39 , 47 , 6 , 50
|
||||
116 , 64 , 85 , 108 , 70 , 57 , 69 , 33 , 67 , 45
|
||||
73 , 2 , 69 , 10 , 32 , 6 , 70 , 58 , 77 , 75
|
||||
112 , 77 , 78 , 122 , 115 , 58 , 95 , 8 , 39 , 41
|
||||
6 , 11 , 55 , 22 , 104 , 9 , 53 , 50 , 84 , 11
|
||||
33 , 86 , 100 , 58 , 120 , 99 , 128 , 29 , 2 , 90
|
||||
11 , 119 , 20 , 45 , 93 , 115 , 70 , 14 , 121 , 56
|
||||
95 , 76 , 21 , 17 , 98 , 33 , 107 , 111 , 99 , 34
|
||||
BIN
BioIBE/lib/bcprov-jdk16-1.46.jar
Normal file
BIN
BioIBE/lib/bcprov-jdk16-1.46.jar
Normal file
Binary file not shown.
BIN
BioIBE/lib/jna-3.2.5.jar
Normal file
BIN
BioIBE/lib/jna-3.2.5.jar
Normal file
Binary file not shown.
BIN
BioIBE/lib/jpbc-api-2.0.0.jar
Normal file
BIN
BioIBE/lib/jpbc-api-2.0.0.jar
Normal file
Binary file not shown.
BIN
BioIBE/lib/jpbc-benchmark-2.0.0.jar
Normal file
BIN
BioIBE/lib/jpbc-benchmark-2.0.0.jar
Normal file
Binary file not shown.
BIN
BioIBE/lib/jpbc-crypto-2.0.0.jar
Normal file
BIN
BioIBE/lib/jpbc-crypto-2.0.0.jar
Normal file
Binary file not shown.
BIN
BioIBE/lib/jpbc-mm-2.0.0.jar
Normal file
BIN
BioIBE/lib/jpbc-mm-2.0.0.jar
Normal file
Binary file not shown.
BIN
BioIBE/lib/jpbc-pbc-2.0.0.jar
Normal file
BIN
BioIBE/lib/jpbc-pbc-2.0.0.jar
Normal file
Binary file not shown.
BIN
BioIBE/lib/jpbc-plaf-2.0.0.jar
Normal file
BIN
BioIBE/lib/jpbc-plaf-2.0.0.jar
Normal file
Binary file not shown.
8
BioIBE/src/a.properties
Normal file
8
BioIBE/src/a.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
type a
|
||||
q 1571
|
||||
r 131
|
||||
h 12
|
||||
exp1 1
|
||||
exp2 7
|
||||
sign0 1
|
||||
sign1 1
|
||||
27
BioIBE/src/bioibe/impl/BioGUIImpl.java
Normal file
27
BioIBE/src/bioibe/impl/BioGUIImpl.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package bioibe.impl;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
/**
|
||||
* ͼ<>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @author 18968
|
||||
*
|
||||
*/
|
||||
public class BioGUIImpl extends JFrame{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
JPanel jp1 ; //<2F><><EFBFBD><EFBFBD>
|
||||
JLabel jl1; //<2F><>ǩ
|
||||
JButton jb1; //<2F><>ť
|
||||
JTextField jtf1; //<2F>ı<EFBFBD><C4B1><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public BioGUIImpl() {
|
||||
// TODO Auto-generated constructor stub
|
||||
jp1 = new JPanel();
|
||||
jl1 = new JLabel("<EFBFBD><EFBFBD>Կ");
|
||||
|
||||
}
|
||||
}
|
||||
222
BioIBE/src/bioibe/impl/BioIBEImpl.java
Normal file
222
BioIBE/src/bioibe/impl/BioIBEImpl.java
Normal file
@@ -0,0 +1,222 @@
|
||||
package bioibe.impl;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
import bioibe.util.BioIBEUtil;
|
||||
import it.unisa.dia.gas.jpbc.Element;
|
||||
import it.unisa.dia.gas.jpbc.Pairing;
|
||||
/**
|
||||
* <20><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
|
||||
* @author 18968
|
||||
*
|
||||
*/
|
||||
public class BioIBEImpl {
|
||||
/**
|
||||
* hash<73><68><EFBFBD><EFBFBD>
|
||||
* @param str
|
||||
* @return
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
public static String shaEncode(String mac_mod) throws Exception {
|
||||
MessageDigest sha = MessageDigest.getInstance("SHA");
|
||||
byte[] mac_mod_bytes=mac_mod.getBytes("UTF-8");
|
||||
byte[] shaBytes = sha.digest(mac_mod_bytes);
|
||||
StringBuffer hexValue = new StringBuffer();
|
||||
for (int i = 0; i < shaBytes.length; i++) {
|
||||
int val = (int)shaBytes[i]&0xff;
|
||||
if (val<16) {
|
||||
hexValue.append("0");
|
||||
}
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
public static String getXOR(String str1,String str2) throws Exception {
|
||||
StringBuffer val1 = new StringBuffer();
|
||||
StringBuffer val2 = new StringBuffer();
|
||||
StringBuffer results = new StringBuffer();
|
||||
if (str1.length()<str2.length()) {
|
||||
for (int i = 0; i < (str2.length()-str1.length()); i++) {
|
||||
val1.append("0");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < (str1.length()-str2.length()); i++) {
|
||||
val2.append("0");
|
||||
}
|
||||
}
|
||||
String strs1 = str1+val1.toString();
|
||||
String strs2 = str2+ val2.toString();
|
||||
byte[] bys1 = strs1.getBytes("UTF-8");
|
||||
byte[] bys2 = strs2.getBytes("UTF-8");
|
||||
//char[] chs1 = strs1.toCharArray();
|
||||
//char[] chs2 = strs2.toCharArray();
|
||||
for (int i = 0; i < bys1.length; i++) {
|
||||
//int vals = (int)bys1[i]^bys2[i];
|
||||
//System.out.println(vals);
|
||||
System.out.print((bys1[i]^bys2[i]) + ":");
|
||||
results.append((char)(bys1[i]^bys2[i]));
|
||||
//results.append((char)Integer.toHexString(bys1[i]^bys2[i]).charAt(0));
|
||||
}
|
||||
return results.toString();
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
long first = System.currentTimeMillis();
|
||||
long end1 = 0;
|
||||
long end2 = 0;
|
||||
BioIBEUtil bioIBEUtil = new BioIBEUtil();
|
||||
Pairing pairing = bioIBEUtil.getPairing();
|
||||
|
||||
System.out.println("--------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>--------------");
|
||||
//MAC<41><43>ַ
|
||||
String macid = "A0481C9D5EA6";
|
||||
System.out.println("Mac<EFBFBD><EFBFBD>ַ:"+macid);
|
||||
//ģ<><C4A3> N
|
||||
String modid = "9923";
|
||||
System.out.println("ģ<EFBFBD><EFBFBD>:"+modid);
|
||||
//macid||modid
|
||||
String mac_mod = macid+modid;
|
||||
//<2F><><EFBFBD><EFBFBD>hashֵ
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
||||
String oxr_p = getXOR(modid, macid);
|
||||
//System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"+oxr_p);
|
||||
System.out.println();
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>ֵ:");
|
||||
String xor_s = getXOR(macid, oxr_p);
|
||||
System.out.println();
|
||||
System.out.println("10<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>ֵ:"+xor_s.substring( 0, modid.length()));
|
||||
//System.out.println();
|
||||
String hash = shaEncode(mac_mod);
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Hashֵ:"+hash);
|
||||
//System.out.println("hash:");
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Mac<EFBFBD><EFBFBD>ַ:");
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String in_macid = scanner.nextLine();
|
||||
String macp_mods = in_macid+xor_s.substring(0,modid.length());
|
||||
//System.out.println("macp_mods"+macp_mods);
|
||||
String hash_s = shaEncode(macp_mods);
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Hashֵ:"+hash_s);
|
||||
if (hash.equals(hash_s)) {
|
||||
//<2F><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
end1 = System.currentTimeMillis();
|
||||
System.out.println("---------------<2D><><EFBFBD>ܽ<DCBD>-----------------");
|
||||
/**
|
||||
System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD>ģ<EFBFBD>");
|
||||
Scanner in = new Scanner(System.in);
|
||||
String str = in.nextLine();
|
||||
*/
|
||||
StringBuffer strMess = new StringBuffer();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int max = 126;
|
||||
int min = 33;
|
||||
int ch = random.nextInt(max)%(max-min+1) + min;
|
||||
strMess.append((char)ch);
|
||||
}
|
||||
//String str = "ahdsa;dksadfiakdas";
|
||||
String str = strMess.toString();
|
||||
char[] chs = str.toCharArray();
|
||||
System.out.println("<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"+str);
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
//Element mess = pairing.getGT().newRandomElement().getImmutable();
|
||||
//System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>" + mess);
|
||||
/**
|
||||
System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD>빫ԿID:");
|
||||
int userBiopkID = in.nextInt();
|
||||
Element[] biopk = bioIBEUtil.getBiopk(userBiopkID);
|
||||
System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˽ԿID:");
|
||||
int userBioskID = in.nextInt();
|
||||
Element[] biosk = bioIBEUtil.getBiosk(userBioskID);
|
||||
*/
|
||||
//Element[] biopk = bioIBEUtil.getBiopk(1);
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>任<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԿID:");
|
||||
int userBiopkID = scanner.nextInt();
|
||||
Element[] biopk = bioIBEUtil.getBiopk(userBiopkID);
|
||||
Element[] biosk = bioIBEUtil.getBiosk(2);
|
||||
//<2F>жϹ<D0B6>˽Կ<CBBD>Ƿ<EFBFBD>ƥ<EFBFBD><C6A5>
|
||||
Element product = pairing.getZr().newZeroElement().getImmutable();
|
||||
for (int i = 0; i < biopk.length; i++) {
|
||||
product = product.add(biopk[i].mul(biosk[i]));
|
||||
//System.out.println(product);
|
||||
}
|
||||
if (product.isZero()) {
|
||||
bioIBEUtil.getMsk();
|
||||
bioIBEUtil.getMpk();
|
||||
bioIBEUtil.getSk();
|
||||
Element mess;
|
||||
StringBuffer sBuffer= new StringBuffer();
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD>ܺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
||||
for (int i = 0; i < chs.length; i++) {
|
||||
System.out.println("<EFBFBD><EFBFBD>"+ i + "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
mess = pairing.getGT().newElement(chs[i]).getImmutable();
|
||||
Element[] ctss = bioIBEUtil.getCt(mess);
|
||||
Element message = bioIBEUtil.getMessage(ctss);
|
||||
String SSL = message.toString();
|
||||
//System.out.println("<22><><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>");
|
||||
//System.out.println(SSL);
|
||||
String[] reStrings = SSL.split("=|,");
|
||||
int reInt = Integer.parseInt(reStrings[1]);
|
||||
//System.out.println(Character.toChars(reInt));
|
||||
sBuffer.append(Character.toChars(reInt));
|
||||
}
|
||||
end2 = System.currentTimeMillis();
|
||||
System.out.println("---------------<2D><><EFBFBD>ܽ<DCBD>---------------");
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID:");
|
||||
int in_sk= scanner.nextInt();
|
||||
if (userBiopkID==in_sk) {
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD>ܺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
|
||||
System.out.println(sBuffer.toString());
|
||||
}else {
|
||||
System.out.println("<EFBFBD><EFBFBD>˽Կ<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD>");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
}else {
|
||||
System.out.println("<EFBFBD><EFBFBD>˽Կ<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD>");
|
||||
}
|
||||
/**
|
||||
bioIBEUtil.getMsk();
|
||||
bioIBEUtil.getMpk();
|
||||
bioIBEUtil.getSk();
|
||||
Element mess;
|
||||
System.out.println("<22><><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>");
|
||||
for (int i = 0; i < chs.length; i++) {
|
||||
mess = pairing.getGT().newElement(chs[i]).getImmutable();
|
||||
bioIBEUtil.getCt(mess);
|
||||
Element message = bioIBEUtil.getMessage();
|
||||
String SSL = message.toString();
|
||||
//System.out.println("<22><><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>");
|
||||
//System.out.println(SSL);
|
||||
String[] reStrings = SSL.split("=|,");
|
||||
int reInt = Integer.parseInt(reStrings[1]);
|
||||
System.out.println(Character.toChars(reInt));
|
||||
}
|
||||
*/
|
||||
/**
|
||||
bioIBEUtil.getCt(mess);
|
||||
Element message = bioIBEUtil.getMessage();
|
||||
String SSL = message.toString();
|
||||
System.out.println("<22><><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>" + message);
|
||||
System.out.println(SSL);
|
||||
*/
|
||||
} else {
|
||||
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD>ƥ<EFBFBD>䣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
System.out.println("---------------ϵͳ<CFB5>ӽ<EFBFBD><D3BD>ܺ<EFBFBD>ʱͳ<CAB1><CDB3>---------------");
|
||||
long end = System.currentTimeMillis();
|
||||
long cost1 = end1 - first;
|
||||
long cost2 = end2 - end1;
|
||||
long cost = end - first;
|
||||
System.out.println("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>ʱ:" + cost1 + "ms");
|
||||
System.out.println("<EFBFBD>ӽ<EFBFBD><EFBFBD>ܺ<EFBFBD>ʱ:" + cost2 + "ms");
|
||||
System.out.println("ϵͳ<EFBFBD>ܺ<EFBFBD>ʱ:" + cost + "ms");
|
||||
}
|
||||
|
||||
}
|
||||
54
BioIBE/src/bioibe/impl/alpha.txt
Normal file
54
BioIBE/src/bioibe/impl/alpha.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
{x=194,y=1107},a
|
||||
{x=535,y=684},b
|
||||
{x=1489,y=1233},c
|
||||
{x=535,y=887},d
|
||||
{x=383,y=415},e
|
||||
{x=102,y=1304},f
|
||||
{x=1226,y=854},g
|
||||
{x=70,y=754},h
|
||||
{x=424,y=1260},i
|
||||
{x=1138,y=993},j
|
||||
{x=384,y=1054},k
|
||||
{x=869,y=1178},l
|
||||
{x=1548,y=760},m
|
||||
{x=626,y=233},n
|
||||
{x=293,y=728},o
|
||||
{x=1534,y=529},p
|
||||
{x=1086,y=1480},q
|
||||
{x=1534,y=1042},r
|
||||
{x=190,y=1385},s
|
||||
{x=1363,y=1371},t
|
||||
{x=297,y=947},u
|
||||
{x=158,y=649},v
|
||||
{x=894,y=654},w
|
||||
{x=879,y=447},x
|
||||
{x=822,y=291},y
|
||||
{x=792,y=997},z
|
||||
{x=1157,y=153},A
|
||||
{x=1299,y=299},B
|
||||
{x=764,y=1043},C
|
||||
{x=259,y=688},D
|
||||
{x=336,y=1296},E
|
||||
{x=1510,y=810},F
|
||||
{x=194,y=464},G
|
||||
{x=987,y=1012},H
|
||||
{x=363,y=14},I
|
||||
{x=535,y=684},J
|
||||
{x=1057,y=398},K
|
||||
{x=1025,y=99},L
|
||||
{x=792,y=574},M
|
||||
{x=605,y=206},N
|
||||
{x=122,y=1508},O
|
||||
{x=1393,y=490},P
|
||||
{x=190,y=186},Q
|
||||
{x=1404,y=632},R
|
||||
{x=1133,y=1467},S
|
||||
{x=1122,y=439},T
|
||||
{x=384,y=517},U
|
||||
{x=64,y=579},V
|
||||
{x=1489,y=338},W
|
||||
{x=1105,y=1505},X
|
||||
{x=1404,y=939},Y
|
||||
{x=184,y=899},Z
|
||||
{x=1299,y=1272},.
|
||||
{x=1157,y=153},,
|
||||
243
BioIBE/src/bioibe/util/BioIBEUtil.java
Normal file
243
BioIBE/src/bioibe/util/BioIBEUtil.java
Normal file
@@ -0,0 +1,243 @@
|
||||
package bioibe.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import it.unisa.dia.gas.jpbc.Element;
|
||||
import it.unisa.dia.gas.jpbc.Pairing;
|
||||
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory;
|
||||
|
||||
public class BioIBEUtil {
|
||||
// TODO Auto-generated method stub
|
||||
//˫<><CBAB><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>
|
||||
Pairing pairing ;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˽Կ
|
||||
Element[] biosk = new Element[10];
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ
|
||||
Element[] biopk = new Element[10];
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Element[] mpk = new Element[13];
|
||||
//<2F><><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD>
|
||||
Element[] msk = new Element[11];
|
||||
//˽Կ
|
||||
Element[] sk = new Element[2];
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
Element[] ct = new Element[12];
|
||||
|
||||
public Pairing getPairing() {
|
||||
pairing = PairingFactory.getPairing("a.properties");
|
||||
return pairing;
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կ
|
||||
@SuppressWarnings("resource")
|
||||
public Element[] getBiopk(int userBiopkID) {
|
||||
|
||||
File file = new File("src/biopk.txt");
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
String tempString = null;
|
||||
int line = 1;
|
||||
while((tempString = reader.readLine())!=null) {
|
||||
//System.out.println("line:" + line);
|
||||
if (line == userBiopkID) {
|
||||
//System.out.println(tempString);
|
||||
String[] strs = tempString.split(",");
|
||||
for (int i = 0; i < strs.length; i++) {
|
||||
biopk[i] = pairing.getZr().newElement(Integer.parseInt(strs[i].trim())).getImmutable();
|
||||
//System.out.println(biopk[i]);
|
||||
}
|
||||
return biopk;
|
||||
}
|
||||
line++;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return biopk;
|
||||
/**
|
||||
biopk[0] =pairing.getZr().newElement(24).getImmutable();
|
||||
biopk[1] =pairing.getZr().newElement(96).getImmutable();
|
||||
biopk[2] =pairing.getZr().newElement(31).getImmutable();
|
||||
biopk[3] =pairing.getZr().newElement(43).getImmutable();
|
||||
biopk[4] =pairing.getZr().newElement(21).getImmutable();
|
||||
biopk[5] =pairing.getZr().newElement(24).getImmutable();
|
||||
biopk[6] =pairing.getZr().newElement(17).getImmutable();
|
||||
biopk[7] =pairing.getZr().newElement(29).getImmutable();
|
||||
biopk[8] =pairing.getZr().newElement(39).getImmutable();
|
||||
biopk[9] =pairing.getZr().newElement(1).getImmutable();
|
||||
return biopk;
|
||||
*/
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˽Կ
|
||||
@SuppressWarnings("resource")
|
||||
public Element[] getBiosk(int userBioskID) {
|
||||
File file = new File("src/biosk.txt");
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
String tempString = null;
|
||||
int line = 1;
|
||||
while((tempString = reader.readLine())!=null) {
|
||||
//System.out.println("line:" + line);
|
||||
if (line == userBioskID) {
|
||||
//System.out.println(tempString);
|
||||
String[] strs = tempString.split(",");
|
||||
for (int i = 0; i < strs.length; i++) {
|
||||
biosk[i] = pairing.getZr().newElement(Integer.parseInt(strs[i].trim())).getImmutable();
|
||||
//System.out.println(biosk[i]);
|
||||
}
|
||||
return biosk;
|
||||
}
|
||||
line++;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return biosk;
|
||||
|
||||
/**
|
||||
biosk[0] =pairing.getZr().newElement(81).getImmutable();
|
||||
biosk[1] =pairing.getZr().newElement(14).getImmutable();
|
||||
biosk[2] =pairing.getZr().newElement(121).getImmutable();
|
||||
biosk[3] =pairing.getZr().newElement(106).getImmutable();
|
||||
biosk[4] =pairing.getZr().newElement(84).getImmutable();
|
||||
biosk[5] =pairing.getZr().newElement(91).getImmutable();
|
||||
biosk[6] =pairing.getZr().newElement(86).getImmutable();
|
||||
biosk[7] =pairing.getZr().newElement(58).getImmutable();
|
||||
biosk[8] =pairing.getZr().newElement(126).getImmutable();
|
||||
biosk[9] =pairing.getZr().newElement(108).getImmutable();
|
||||
return biosk;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD>Թ<EFBFBD>˽Կ<CBBD>Ƿ<EFBFBD>ƥ<EFBFBD>伴<EFBFBD>ڻ<EFBFBD><DABB>Ƿ<EFBFBD>Ϊ0
|
||||
|
||||
Element product = pairing.getZr().newZeroElement();
|
||||
for (int i = 0; i < biopk.length; i++) {
|
||||
product = product.add(biopk[i].mul(biosk[i]));
|
||||
}
|
||||
System.out.println("product:"+ product);
|
||||
*/
|
||||
//<2F><><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD>
|
||||
public Element[] getMsk() {
|
||||
for (int i = 0; i < msk.length; i++) {
|
||||
msk[i] = pairing.getZr().newRandomElement().getImmutable();
|
||||
//System.out.print("msk["+ i +"]:" + msk[i] + " ");
|
||||
}
|
||||
return msk;
|
||||
}
|
||||
|
||||
//System.out.println();
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public Element[] getMpk() {
|
||||
//<2F><><EFBFBD><EFBFBD>Ԫ
|
||||
Element g = pairing.getG1().newRandomElement().getImmutable();
|
||||
mpk[0] = g.getImmutable();
|
||||
//System.out.print("mpk[0]:" + mpk[0] + " ");
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 131 Ҳ<><D2B2><EFBFBD><EFBFBD>0
|
||||
Element p = pairing.getZr().newElement(131).getImmutable();
|
||||
mpk[1] = p.getImmutable();
|
||||
//System.out.print("mpk[1]:" + mpk[1] + " ");
|
||||
for (int i = 2; i < mpk.length-1; i++) {
|
||||
mpk[i] = g.powZn(msk[i-2]).getImmutable();
|
||||
//System.out.print("mpk["+ i + "]" + mpk[i] + " ");
|
||||
}
|
||||
// u
|
||||
Element u_1 = pairing.pairing(g, g).getImmutable();
|
||||
Element u = u_1.powZn(msk[msk.length-1]).getImmutable();
|
||||
mpk[mpk.length-1] = u.getImmutable();
|
||||
//System.out.println("mpk[" + (mpk.length-1) + "]"+ mpk[mpk.length-1] + " ");
|
||||
return mpk;
|
||||
}
|
||||
|
||||
//˽Կ
|
||||
public Element[] getSk() {
|
||||
Element sum_a_z = pairing.getZr().newElement(0).getImmutable();
|
||||
for (int i = 0; i < biosk.length; i++) {
|
||||
sum_a_z = sum_a_z.add(msk[i].mul(biosk[i])).getImmutable();
|
||||
//System.out.print("sum:"+sum_a_z + " : ");
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> t
|
||||
Element t = pairing.getZr().newRandomElement().getImmutable();
|
||||
Element sum_t = t.mul(sum_a_z).getImmutable();
|
||||
Element sum_b_t = msk[msk.length-1].add(sum_t).getImmutable();
|
||||
sk[0] = mpk[0].powZn(sum_b_t).getImmutable();
|
||||
sk[1] = mpk[0].powZn(t).getImmutable();
|
||||
return sk;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
public Element[] getCt(Element mess) {
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> r
|
||||
Element r = pairing.getZr().newRandomElement().getImmutable();
|
||||
//System.out.println("r:" + r);
|
||||
//System.out.println(mpk[mpk.length-1]);
|
||||
Element c_m_r = mpk[mpk.length-1].powZn(r).getImmutable();
|
||||
//Element c_m_r_t = pairing.pairing(g, g).powZn(msk[msk.length-1].mul(r));
|
||||
//<2F><><EFBFBD><EFBFBD> m
|
||||
//Element m = pairing.getGT().newRandomElement().getImmutable();
|
||||
Element m = mess.duplicate().getImmutable();
|
||||
//System.out.println("ԭʼ<D4AD><CABC><EFBFBD><EFBFBD>m:" + m);
|
||||
Element c_m = c_m_r.mul(m).getImmutable();
|
||||
ct[0] = c_m.getImmutable();
|
||||
Element c_0 = mpk[0].powZn(r).getImmutable();
|
||||
System.out.print("ct[0]"+ ct[0] + " , ");
|
||||
ct[1] = c_0.getImmutable();
|
||||
System.out.print("ct[1]"+ ct[1] + " , ");
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> s
|
||||
Element s = pairing.getZr().newRandomElement().getImmutable();
|
||||
Element g_r = pairing.getG1().newZeroElement().getImmutable();
|
||||
Element g_s_w = pairing.getG1().newZeroElement().getImmutable();
|
||||
for (int i = 2; i < ct.length; i++) {
|
||||
//g_r = mpk[i].powZn(r);
|
||||
//g_s_w = mpk[0].powZn(s.mulZn(biopk[i-2]));
|
||||
g_r = mpk[i].powZn(r).getImmutable();
|
||||
//g_s_w = mpk[0].powZn(s.mul(biopk[i-2]));
|
||||
g_s_w = mpk[0].powZn(s.mul(biopk[i-2])).getImmutable();
|
||||
//System.out.println("g_r" + g_r);
|
||||
//System.out.println("g_s_w" + g_s_w);
|
||||
ct[i] = g_r.mul(g_s_w).getImmutable();
|
||||
System.out.print("ct[" +i+ "]" +ct[i] + " , ");
|
||||
if (i==5) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
return ct;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
public Element getMessage(Element[] ctss) {
|
||||
Element e_0_0 = pairing.getG1().newOneElement().getImmutable();
|
||||
//System.out.println("e_0_0:*******" + e_0_0);
|
||||
for (int i = 2; i < ctss.length; i++) {
|
||||
//System.out.println(ct.length);
|
||||
e_0_0 = e_0_0.mul(ctss[i].powZn(biosk[i-2]));
|
||||
//System.out.println("e_0_0:" + e_0_0);
|
||||
}
|
||||
Element e_0 = pairing.pairing(sk[1], e_0_0).getImmutable();
|
||||
Element e_1 = pairing.pairing(sk[0], ctss[1]).getImmutable();
|
||||
//Element e_1_p = e_1.powZn(pairing.getZr().newElement(130));
|
||||
Element M = ctss[0].div(e_1).mul(e_0).getImmutable();
|
||||
//Element M = ct[0].div(e_1).mul(e_1);
|
||||
//System.out.println(M_e);
|
||||
//System.out.println("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>M:"+M);
|
||||
//System.out.println(ct[0]);
|
||||
return M;
|
||||
}
|
||||
}
|
||||
10
BioIBE/src/biopk.txt
Normal file
10
BioIBE/src/biopk.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
110 , 121 , 121 , 89 , 118 , 52 , 108 , 115 , 113 , 1
|
||||
3 , 79 , 129 , 77 , 45 , 6 , 103 , 82 , 81 , 1
|
||||
112 , 53 , 0 , 3 , 15 , 2 , 118 , 34 , 118 , 1
|
||||
126 , 56 , 110 , 59 , 99 , 115 , 85 , 42 , 124 , 1
|
||||
16 , 87 , 27 , 95 , 87 , 79 , 16 , 40 , 18 , 1
|
||||
19 , 115 , 97 , 119 , 37 , 57 , 99 , 8 , 58 , 1
|
||||
60 , 82 , 43 , 13 , 106 , 86 , 70 , 10 , 6 , 1
|
||||
34 , 67 , 108 , 4 , 57 , 14 , 61 , 45 , 78 , 1
|
||||
106 , 69 , 70 , 116 , 114 , 108 , 62 , 101 , 42 , 1
|
||||
67 , 96 , 104 , 59 , 24 , 107 , 72 , 75 , 107 , 1
|
||||
10
BioIBE/src/biosk.txt
Normal file
10
BioIBE/src/biosk.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
93 , 79 , 36 , 92 , 23 , 114 , 89 , 94 , 20 , 9
|
||||
28 , 96 , 67 , 36 , 47 , 69 , 9 , 57 , 5 , 23
|
||||
102 , 129 , 98 , 96 , 36 , 11 , 39 , 47 , 6 , 50
|
||||
116 , 64 , 85 , 108 , 70 , 57 , 69 , 33 , 67 , 45
|
||||
73 , 2 , 69 , 10 , 32 , 6 , 70 , 58 , 77 , 75
|
||||
112 , 77 , 78 , 122 , 115 , 58 , 95 , 8 , 39 , 41
|
||||
6 , 11 , 55 , 22 , 104 , 9 , 53 , 50 , 84 , 11
|
||||
33 , 86 , 100 , 58 , 120 , 99 , 128 , 29 , 2 , 90
|
||||
11 , 119 , 20 , 45 , 93 , 115 , 70 , 14 , 121 , 56
|
||||
95 , 76 , 21 , 17 , 98 , 33 , 107 , 111 , 99 , 34
|
||||
Reference in New Issue
Block a user