Guillaume
Guillaume

Reputation: 356

Decode and encode in Base45 in Java

I am following with great interest the digital covid certificate project in java: https://github.com/ehn-dcc-development/

More specifically, for Java and to decode the pass: https://github.com/GaetanoPiazzolla/greenpass-decode

Using this code, to decode the base45 string that we read from the QR code, we have:

byte[] bytecompressed = Base45.getDecoder().decode(withoutPrefix);

I would like to encode this same string back, so I am trying the following:

byte[] byteCompressedNew = Base45.getEncoder().encode(bytecompressed);

But this results in the following error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -23 out of bounds for length 45 at nl.minvws.encoding.Base45$Encoder.encode(Base45.java:74)

At this line of code in the base45 module:

result[resultIndex++] = toBase45[value % 45];

It would be great if you could help me understand what I do wrong.

Thank you very much!

Upvotes: 2

Views: 2753

Answers (1)

Thomas Kläger
Thomas Kläger

Reputation: 21630

You need to update your dependency from version 0.0.2 to 0.0.3 (released on April 6, 2021 with a bug fix for exactly this problem)

io.github.ehn-digital-green-development:base45:0.0.3

For maven:

<dependency>
  <groupId>io.github.ehn-digital-green-development</groupId>
  <artifactId>base45</artifactId>
  <version>0.0.3</version>
</dependency>

Upvotes: 6

Related Questions