mirror of https://github.com/captn3m0/epicqr.git
Adds Java code
This commit is contained in:
parent
6b429de1de
commit
90af000a33
|
@ -1 +1,4 @@
|
|||
library.zip
|
||||
haxe-build.zip
|
||||
build/
|
||||
|
||||
*.jar
|
2
SPEC.md
2
SPEC.md
|
@ -69,7 +69,7 @@ Note the extra space.
|
|||
##### Encoded Base64
|
||||
|
||||
```text
|
||||
7+NGHfxDoqjXjk6iU0U6yTYhjWktxVe6eijj+9Nf36VYpzgIb+qIzxS6VSukYt6ANFCzuM6mZ4AO9oO4FFDAVw==
|
||||
dbhvecY6Roa4NF3gAzEbkTibZZzXAEYpMg8197BQWMS2+ID24FGDKWB5IEcuxjsA81ChprhSO3EsjKMRDbBWLg==
|
||||
```
|
||||
|
||||
See the recipe on [CyberChef][cyberchef].
|
||||
|
|
12
release.sh
12
release.sh
|
@ -1,4 +1,10 @@
|
|||
#!/bin/sh
|
||||
rm -f library.zip
|
||||
zip -r library.zip src LICENSE *.md *.json *.hxml
|
||||
haxelib submit library.zip $(pass show Dev/lib.haxe.org) --always
|
||||
# Haxe
|
||||
rm -f haxe-build.zip
|
||||
zip -r haxe-build.zip src LICENSE *.md *.json *.hxml
|
||||
haxelib submit haxe-build.zip $(pass show Dev/lib.haxe.org) --always
|
||||
rm -f haxe-build.zip
|
||||
|
||||
# Java
|
||||
javac -cp src src/eci/*.java -d build/
|
||||
jar -cf epicqr-release.jar build/*
|
|
@ -13,7 +13,7 @@ class EpicQR{
|
|||
// public static inline var SALT:String = "FSwI.qT";
|
||||
|
||||
public static inline var IV:String = "H76$suq23_po(8sD";
|
||||
public static inline var KEY:String = "X_4k$uq23FSwI.qT"; // KEY+SALT
|
||||
public static inline var KEY:String = "X_4k$uq23FSwI.qT"; // KEY_PREFIX + SALT
|
||||
|
||||
static function decode(input:String){
|
||||
var cipherText:Bytes = Base64.decode(input);
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package eci;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class EpicQR {
|
||||
// static String KEY_SEED = "tHzHtCcDd3V6p_9dOnse|_SX_4k$uq23.qT.L.(MgyJ7UH4n921J6UlKeck_S0Jl2znUY8CiMKyklWf2";
|
||||
// static String KEY_PREFIX = "X_4k$uq23"; // SUBSTR(KEY_SEED, 23, 32)
|
||||
// static String SALT = "FSwI.qT";
|
||||
static String IV = "H76$suq23_po(8sD";
|
||||
static String KEY = "X_4k$uq23FSwI.qT"; // KEY_PREFIX + SALT
|
||||
|
||||
private static SecretKeySpec getKey() {
|
||||
return new SecretKeySpec(KEY.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
}
|
||||
|
||||
private static Cipher getCipher() throws NoSuchAlgorithmException, InvalidKeyException,NoSuchPaddingException,InvalidAlgorithmParameterException {
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, getKey(), new IvParameterSpec(IV.getBytes()));
|
||||
return cipher;
|
||||
}
|
||||
|
||||
public static Result decode(String input) {
|
||||
try {
|
||||
byte[] decryptedBytes = getCipher().doFinal(Base64.getDecoder().decode(input));
|
||||
String j = new String(decryptedBytes);
|
||||
return extractValue(j, "epic_no", "unique_generated_id");
|
||||
} catch (Exception exception) {
|
||||
throw new RuntimeException("Failed to decode", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static Result extractValue(String jsonString, String k1, String k2) {
|
||||
final String regex = "\\{\\\"epic_no\\\":\\\"([A-Z]{3}\\d{7})\\\",\\\"unique_generated_id\\\":(\\d+)\\}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(jsonString);
|
||||
|
||||
if (matcher.find()) {
|
||||
return new Result(matcher.group(1), Integer.parseInt(matcher.group(2)));
|
||||
} else {
|
||||
throw new RuntimeException("Failed to parse JSON");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,9 +2,9 @@ package eci;
|
|||
|
||||
class Result {
|
||||
public var epic:String;
|
||||
public var id:String;
|
||||
public var id:Int;
|
||||
|
||||
public function new(epic: String, id: String) {
|
||||
public function new(epic: String, id: Int) {
|
||||
this.epic = epic;
|
||||
this.id = id;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package eci;
|
||||
|
||||
public class Result{
|
||||
public String epic;
|
||||
public int id;
|
||||
|
||||
// constructor
|
||||
public Result(String epic, int id){
|
||||
this.epic = epic;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
## Tests for Java
|
||||
javac -cp src/ test/Test.java
|
||||
java -enableassertions -cp src:test Test
|
Binary file not shown.
|
@ -0,0 +1,11 @@
|
|||
import eci.Result;
|
||||
import eci.EpicQR;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
String e1 = "dbhvecY6Roa4NF3gAzEbkTibZZzXAEYpMg8197BQWMS2+ID24FGDKWB5IEcuxjsA81ChprhSO3EsjKMRDbBWLg==";
|
||||
Result r1 = EpicQR.decode(e1);
|
||||
assert r1.epic.equals("ABC1234566") : "Invalid EPIC";
|
||||
assert r1.id == 1234 : "Invalid Unique ID";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"input": "{\"epic_no\":\"ABC1234566\",\"unique_generated_id\":1234}",
|
||||
"output": "dbhvecY6Roa4NF3gAzEbkTibZZzXAEYpMg8197BQWMS2+ID24FGDKWB5IEcuxjsA81ChprhSO3EsjKMRDbBWLg=="
|
||||
}
|
Loading…
Reference in New Issue