-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPublicKey.java
More file actions
64 lines (53 loc) · 1.68 KB
/
PublicKey.java
File metadata and controls
64 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package ECC;
import java.io.File;
import java.io.PrintStream;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
/**
* The key consists of: c, the elliptic curve used in the calculations, pK, the
* point obtained from k * G, where k is the corresponding private key and G is
* the base point of c.
*/
public class PublicKey {
private EllipticCurve c;
private Point pK;
public PublicKey(EllipticCurve c, Point pK) {
this.c = c;
this.pK = pK;
}
public PublicKey(String pathFile) {
try {
List<String> lines = Files.readAllLines(Paths.get(pathFile), StandardCharsets.UTF_8);
BigInteger a = new BigInteger(lines.get(0), 16);
BigInteger b = new BigInteger(lines.get(1), 16);
BigInteger p = new BigInteger(lines.get(2), 16);
BigInteger g1 = new BigInteger(lines.get(3), 16);
BigInteger g2 = new BigInteger(lines.get(4), 16);
BigInteger pK1 = new BigInteger(lines.get(5), 16);
BigInteger pK2 = new BigInteger(lines.get(6), 16);
EllipticCurve eC = new EllipticCurve(a, b, p, new Point(g1, g2));
Point eCP = new Point(pK1, pK2);
this.c = eC;
this.pK = eCP;
} catch (Exception e) {
}
}
public EllipticCurve getCurve() {
return c;
}
public void setCurve(EllipticCurve c) {
this.c = c;
}
public Point getKey() {
return pK;
}
public void setKey(Point pK) {
this.pK = pK;
}
public Point getBasePoint() {
return c.getBasePoint();
}
}