bc-java
bc-java copied to clipboard
invalid characters encountered in Hex string while decoding SolidityType string
I am trying to parse a RawTransaction Data using : https://github.com/CoboVault/cobo-vault-cold/blob/master/coinlib/src/main/java/com/cobo/coinlib/coins/ETH/SolidityType.java#L303
But when I try to pass 08414243445f454647 - it throws "org.bouncycastle.util.encoders.DecoderException: exception decoding Hex string: invalid characters encountered in Hex string". This should evaluate to "ABCD_EFG"
It's not able to understand 08 as length of the string. If I pass 00 instead of 08 at the beginning, it's able to parse but gives empty string.
I tried with following versions:
<dependency>
<groupId>com.madgag.spongycastle</groupId>
<artifactId>core</artifactId>
<version>1.58.0.0</version>
</dependency>
and
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.68</version>
</dependency>
Please let me know if you need any further details
The line that you point to in StringType reads
return new String(Hex.decode(super.decode(encoded, offset)), StandardCharsets.UTF_8);
The underlying decode method in class BytesType has as its return statement
return "0x"+Hex.toHexString(Arrays.copyOfRange(encoded, offset, offset + len));
and there you have your problem.
The characters "0x" are being prefixed to the hex string that is passed to Hex.decode()
the letter x is not a valid hex character and is therefore rejected.
Regarded as dealt with.