I’m trying to Hex encode a string, because we have a Java spring security password database, and one of the steps in encrypting it is Hex encoding. If I can do this in perl, then I can use perl apps with the same authentication database. The algorithm is below in Java, but surely there should be a Perl library function somewhere that can do it for me?
public static char[] encode(byte[] bytes) {
final int nBytes = bytes.length;
char[] result = new char[2 * nBytes];
int j = 0;
for (byte aByte : bytes) {
// Char for top 4 bits
result[j++] = HEX[(0xF0 & aByte) >>> 4];
// Bottom 4
result[j++] = HEX[(0x0F & aByte)];
}
return result;
}
Tried searching for forums for a solution
New contributor
ccthecc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.