Skip to content

Commit

Permalink
[APPC-662] - ECDSASignature toHex() now returns a normalized encoded …
Browse files Browse the repository at this point in the history
…string.
  • Loading branch information
FredericoSantinho committed Oct 8, 2018
1 parent 984089a commit 0c2271f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ethereumj-android/src/main/java/ethereumj/crypto/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,9 @@ public boolean isPubKeyCanonical() {
* components can be useful for doing further EC maths on them.
*/
public static class ECDSASignature {

private static final int SIGNATURE_HEX_LENGTH = 130;

/**
* The two components of the signature.
*/
Expand Down Expand Up @@ -1029,7 +1032,16 @@ public byte[] toByteArray() {
}

public String toHex() {
return Hex.toHexString(toByteArray());
return normalize(Hex.toHexString(toByteArray()));
}

private String normalize(String s) {
StringBuilder builder = new StringBuilder(s);

for (int i = 0; i < (SIGNATURE_HEX_LENGTH - s.length()); i++) {
builder.insert(0, '0');
}
return builder.toString();
}

@Override public int hashCode() {
Expand Down

0 comments on commit 0c2271f

Please sign in to comment.