/** * 从本地导入公钥 * * @param path * @return */ public ECPoint importPublicKey(String path) { File file = new File(path); try { if (!file.exists()) return null; FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte buffer[] = new byte[16]; int size; while ((size = fis.read(buffer)) != -1) { baos.write(buffer, 0, size); } fis.close(); return curve.decodePoint(baos.toByteArray()); } catch (IOException e) { e.printStackTrace(); } return null; }
/** * 密钥确认最后一步 * * @param entity 传输实体 */ public void keyExchange_4(TransportEntity entity) { byte[] xV = V.getXCoord().toBigInteger().toByteArray(); byte[] yV = V.getYCoord().toBigInteger().toByteArray(); ECPoint RA = curve.decodePoint(entity.R).normalize(); byte[] s2 = sm3hash(new byte[]{0x03}, yV, sm3hash(xV, entity.Z, this.Z, RA.getXCoord().toBigInteger().toByteArray(), RA.getYCoord().toBigInteger().toByteArray(), this.RA.getXCoord().toBigInteger().toByteArray(), this.RA.getYCoord().toBigInteger().toByteArray())); if (Arrays.equals(entity.S, s2)) System.out.println("A->B 密钥确认成功"); else System.out.println("A->B 密钥确认失败"); } }
ECPoint RB = curve.decodePoint(entity.R).normalize(); ECPoint bPublicKey = curve.decodePoint(entity.K).normalize(); ECPoint temp = bPublicKey.add(RB.multiply(x2).normalize()).normalize(); ECPoint U = temp.multiply(ecc_bc_spec.getH().multiply(tA)).normalize();
System.arraycopy(encryptData, 0, C1Byte, 0, C1Byte.length); ECPoint C1 = curve.decodePoint(C1Byte).normalize();
System.arraycopy(encryptData, 0, c1Byte, 0, c1Byte.length); ECPoint c1 = curve.decodePoint(c1Byte).normalize();
ECPoint RB = curve.decodePoint(entity.R).normalize(); ECPoint bPublicKey=curve.decodePoint(entity.K).normalize(); ECPoint temp = bPublicKey.add(RB.multiply(x2).normalize()).normalize(); ECPoint U = temp.multiply(ecc_bc_spec.getH().multiply(tA)).normalize();
ECPoint RA = curve.decodePoint(entity.R).normalize(); ECPoint aPublicKey=curve.decodePoint(entity.K).normalize(); ECPoint temp = aPublicKey.add(RA.multiply(x1).normalize()).normalize(); ECPoint V = temp.multiply(ecc_bc_spec.getH().multiply(tB)).normalize();
ECPoint RB = curve.decodePoint(entity.r).normalize(); ECPoint bPublicKey = curve.decodePoint(entity.k).normalize(); ECPoint temp = bPublicKey.add(RB.multiply(x2).normalize()).normalize(); ECPoint u = temp.multiply(ecc_bc_spec.getH().multiply(tA)).normalize();
ECPoint RA = curve.decodePoint(entity.r).normalize(); ECPoint aPublicKey = curve.decodePoint(entity.k).normalize(); ECPoint temp = aPublicKey.add(RA.multiply(x1).normalize()).normalize(); ECPoint v = temp.multiply(ecc_bc_spec.getH().multiply(tB)).normalize();
/** * 从本地导入公钥 * * @param path * @return */ public ECPoint importPublicKey(String path) { File file = new File(path); try { if (!file.exists()) return null; FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte buffer[] = new byte[16]; int size; while ((size = fis.read(buffer)) != -1) { baos.write(buffer, 0, size); } fis.close(); return curve.decodePoint(baos.toByteArray()); } catch (IOException e) { e.printStackTrace(); } return null; }
/** * 密钥确认最后一步 * * @param entity 传输实体 */ public void keyExchange_4(TransportEntity entity) { byte[] xV = V.getXCoord().toBigInteger().toByteArray(); byte[] yV = V.getYCoord().toBigInteger().toByteArray(); ECPoint RA = curve.decodePoint(entity.R).normalize(); byte[] s2= sm3hash(new byte[] { 0x03 }, yV, sm3hash(xV, entity.Z, this.Z, RA.getXCoord().toBigInteger().toByteArray(), RA.getYCoord().toBigInteger().toByteArray(), this.RA.getXCoord().toBigInteger().toByteArray(), this.RA.getYCoord().toBigInteger().toByteArray())); if(Arrays.equals(entity.S, s2)) System.out.println("A->B 密钥确认成功"); else System.out.println("A->B 密钥确认失败"); } }
public ECPoint importPublicKey(String path) { File file = new File(path); try { if (!file.exists()) { return null; } FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[16]; int size; while ((size = fis.read(buffer)) != -1) { baos.write(buffer, 0, size); } fis.close(); return curve.decodePoint(baos.toByteArray()); } catch (IOException e) { e.printStackTrace(); } return null; }
public void keyExchange_4(TransportEntity entity) { byte[] xV = v.getXCoord().toBigInteger().toByteArray(); byte[] yV = v.getYCoord().toBigInteger().toByteArray(); ECPoint RA = curve.decodePoint(entity.r).normalize(); byte[] s2 = sm3hash(new byte[] { 0x03 }, yV, sm3hash(xV, entity.z, this.z, RA.getXCoord().toBigInteger().toByteArray(), RA.getYCoord().toBigInteger().toByteArray(), this.ra.getXCoord().toBigInteger().toByteArray(), this.ra.getYCoord().toBigInteger().toByteArray())); if (Arrays.equals(entity.s, s2)) { System.out.println("A->B 密钥确认成功"); } else { System.out.println("A->B 密钥确认失败"); } } }
public ECPoint toPublicKey(byte [] publickey) { return curve.decodePoint(publickey); }
System.arraycopy(encryptData, 0, C1Byte, 0, C1Byte.length); ECPoint C1 = curve.decodePoint(C1Byte).normalize();
ECPoint RA = curve.decodePoint(entity.R).normalize(); ECPoint aPublicKey = curve.decodePoint(entity.K).normalize(); ECPoint temp = aPublicKey.add(RA.multiply(x1).normalize()).normalize(); ECPoint V = temp.multiply(ecc_bc_spec.getH().multiply(tB)).normalize();