11package com .genexus .securityapicommons .encoders ;
22
3- import org .bouncycastle .util .Strings ;
43import org .bouncycastle .util .encoders .Hex ;
54
65import 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