List of utility methods to do XML Base64 Encode Decode
String | encodeBase64(String input) Creates a base 64 encoded string from the given input string. return DatatypeConverter.printBase64Binary(input.getBytes(StandardCharsets.UTF_8));
|
String | encodeBase64(String stringValue) encode Base byte[] bytesValue = stringValue.getBytes("UTF-8"); String encodedValue = DatatypeConverter.printBase64Binary(bytesValue); return encodedValue; |
String | encodeBase64Binary(byte[] data) encode Base Binary return DatatypeConverter.printBase64Binary(data);
|
String | fromBase64(String base64) from Base byte[] encodedHelloBytes = DatatypeConverter.parseBase64Binary(base64); return new String(encodedHelloBytes, StandardCharsets.UTF_8); |
byte[] | fromBase64(String hex) Converts a string of hexadecimal characters into a byte array. return DatatypeConverter.parseBase64Binary(hex);
|
String | getBase64(byte[] bytes) get Base String h = DatatypeConverter.printBase64Binary(bytes); h = h.replaceFirst("=*$", ""); h = h.replace('+', '-'); h = h.replace('/', '_'); return h; |
String | getHashBase64(String origStr, String digestAlgorithm) get Hash Base MessageDigest sha = MessageDigest.getInstance(digestAlgorithm); byte[] resultDigest = sha.digest(origStr.getBytes()); return DatatypeConverter.printBase64Binary(resultDigest); |
byte[] | readBase64Bytes(String str) read Base Bytes return DatatypeConverter.parseBase64Binary(str);
|
String | readFileToBase64(String filePath) Lee todos los bytes de un archivo en particular y lo convierte a un string en Base64 Path path = FileSystems.getDefault().getPath(filePath); byte[] bytesFromFile = Files.readAllBytes(path); return byteToBase64(bytesFromFile); |
String | sha256SaltBase64(String password, String salt) sha256 encryption with salt. try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.reset(); byte[] binaryData = digest.digest((salt + password).getBytes("UTF-8")); return DatatypeConverter.printBase64Binary(binaryData); } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { throw new Exception("Error al encriptar el password.", e); |