Last active
October 27, 2021 20:40
-
-
Save GaetanoPiazzolla/864e7471ea33788bca898fa8e0179b8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 - read text from file | |
File file = new File("C://temp/green-pass.jpg"); | |
BufferedImage bufferedImage = ImageIO.read(file); | |
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); | |
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); | |
Result result = new MultiFormatReader().decode(bitmap); | |
String text = result.getText(); | |
// 2 - remove prefix "HC1:" and decode base45 string | |
byte[] bytecompressed = Base45.getDecoder().decode(text.substring(4)); | |
// 3 - inflate string using zlib | |
Inflater inflater = new Inflater(); | |
inflater.setInput(bytecompressed); | |
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bytecompressed.length); | |
byte[] buffer = new byte[BUFFER_SIZE]; | |
while (!inflater.finished()) { | |
final int count = inflater.inflate(buffer); | |
outputStream.write(buffer, 0, count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related to medium article
https://gae-piaz.medium.com/green-pass-qr-code-signature-verification-java-f742079cc88