-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpatioIO.java
More file actions
41 lines (33 loc) · 1.17 KB
/
SpatioIO.java
File metadata and controls
41 lines (33 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
package io.spatio;
import java.time.Instant;
public class SpatioIO {
private final SpatioSigner signer;
public SpatioIO() throws Exception {
this.signer = new SpatioSigner();
}
public SpatioCertificate generateFromIP() {
double[] coords = SpatioGeoLocator.getCurrentLocation();
return generateFromCoordinates(coords[0], coords[1]);
}
public SpatioCertificate generateFromCoordinates(double latitude, double longitude) {
Instant now = Instant.now();
String hash = SpatioHash.compute(latitude, longitude, now);
try {
String signature = signer.sign(hash);
// sauvegegarder vers le serveur sécurisé de certification
return new SpatioCertificate(latitude, longitude, now, hash, signature);
} catch (Exception e) {
throw new RuntimeException("Erreur lors de la signature", e);
}
}
public boolean verify(SpatioCertificate cert) {
try {
return signer.verify(cert.hash(), cert.signature());
} catch (Exception e) {
return false;
}
}
public SpatioSigner getSigner() {
return signer;
}
}