Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit f8b3e85

Browse files
authored
Merge pull request #11 from genexuslabs/issue#82425
Fix encodings for hexadecimal functions
2 parents 436de6b + 09d35a9 commit f8b3e85

File tree

1 file changed

+14
-5
lines changed
  • SecurityAPICommons/src/main/java/com/genexus/securityapicommons/encoders

1 file changed

+14
-5
lines changed

SecurityAPICommons/src/main/java/com/genexus/securityapicommons/encoders/HexaEncoder.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.genexus.securityapicommons.encoders;
22

3-
import org.bouncycastle.util.Strings;
43
import org.bouncycastle.util.encoders.Hex;
54

65
import com.genexus.securityapicommons.commons.SecurityAPIObject;
6+
import com.genexus.securityapicommons.config.EncodingUtil;
77

88
/**
99
* @author sgrampone
@@ -24,8 +24,12 @@ public HexaEncoder() {
2424
* @return String Hexa hexadecimal representation of plainText
2525
*/
2626
public String toHexa(String plainText) {
27-
28-
byte[] stringBytes = Strings.toByteArray(plainText);
27+
EncodingUtil eu = new EncodingUtil();
28+
byte[] stringBytes = eu.getBytes(plainText);
29+
if (eu.hasError()) {
30+
this.error = eu.getError();
31+
return "";
32+
}
2933
StringBuilder sb = new StringBuilder();
3034
for (byte b : stringBytes) {
3135
sb.append(String.format("%02X ", b));
@@ -47,7 +51,12 @@ public String toHexa(String plainText) {
4751
public String fromHexa(String stringHexa) {
4852

4953
byte[] resBytes = Hex.decode(stringHexa);
50-
String result = Strings.fromByteArray(resBytes);
54+
EncodingUtil eu = new EncodingUtil();
55+
String result = eu.getString(resBytes);
56+
if (eu.hasError()) {
57+
this.error = eu.getError();
58+
return "";
59+
}
5160
if (result == null || result.length() == 0) {
5261
this.error.setError("HE002", "Error decoding hexa");
5362
return "";
@@ -56,4 +65,4 @@ public String fromHexa(String stringHexa) {
5665
return result;
5766
}
5867

59-
}
68+
}

0 commit comments

Comments
 (0)