forked from DNAProject/DNA-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathECC.java
More file actions
43 lines (35 loc) · 1.17 KB
/
Copy pathECC.java
File metadata and controls
43 lines (35 loc) · 1.17 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
package DNA.Cryptography;
import java.security.*;
import org.bouncycastle.asn1.x9.*;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.math.ec.ECPoint;
import DNA.Helper;
public class ECC {
private static final X9ECParameters secp256r1nc = ECNamedCurveTable.getByName("secp256r1");
public static final ECDomainParameters secp256r1 = new ECDomainParameters(secp256r1nc.getCurve(), secp256r1nc.getG(), secp256r1nc.getN(), secp256r1nc.getH(), secp256r1nc.getSeed());
public static int compare(ECPoint a, ECPoint b) {
if (a == b) {
return 0;
}
int result = a.getXCoord().toBigInteger().compareTo(b.getXCoord().toBigInteger());
if (result != 0) {
return result;
}
return a.getYCoord().toBigInteger().compareTo(b.getYCoord().toBigInteger());
}
public static byte[] generateKey(int len) {
byte[] key = new byte[len];
SecureRandom sr = new SecureRandom();
sr.nextBytes(key);
return key;
}
public static byte[] generateKey() {
byte[] key = new byte[32];
SecureRandom sr = new SecureRandom();
sr.nextBytes(key);
return key;
}
public static String toString(ECPoint p) {
return Helper.toHexString(p.getEncoded(true));
}
}