Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.genexus.securityapicommons.encoders;

import org.bouncycastle.util.Strings;
import org.bouncycastle.util.encoders.Hex;

import com.genexus.securityapicommons.commons.SecurityAPIObject;
import com.genexus.securityapicommons.config.EncodingUtil;

/**
* @author sgrampone
Expand All @@ -24,8 +24,12 @@ public HexaEncoder() {
* @return String Hexa hexadecimal representation of plainText
*/
public String toHexa(String plainText) {

byte[] stringBytes = Strings.toByteArray(plainText);
EncodingUtil eu = new EncodingUtil();
byte[] stringBytes = eu.getBytes(plainText);
if (eu.hasError()) {
this.error = eu.getError();
return "";
}
StringBuilder sb = new StringBuilder();
for (byte b : stringBytes) {
sb.append(String.format("%02X ", b));
Expand All @@ -47,7 +51,12 @@ public String toHexa(String plainText) {
public String fromHexa(String stringHexa) {

byte[] resBytes = Hex.decode(stringHexa);
String result = Strings.fromByteArray(resBytes);
EncodingUtil eu = new EncodingUtil();
String result = eu.getString(resBytes);
if (eu.hasError()) {
this.error = eu.getError();
return "";
}
if (result == null || result.length() == 0) {
this.error.setError("HE002", "Error decoding hexa");
return "";
Expand All @@ -56,4 +65,4 @@ public String fromHexa(String stringHexa) {
return result;
}

}
}