how to generate base64 string by normal string.
ReportQuestion
1 year ago 577 views
Use this 2 Function to get your result.
public static String getSha256Hash(String password) { try { MessageDigest digest = null; try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); } digest.reset(); return bin2hex(digest.digest(password.getBytes())); } catch (Exception ignored) { return null; } }
private static String bin2hex(byte[] data) { StringBuilder hex = new StringBuilder(data.length * 2); for (byte b : data) hex.append(String.format("%02x", b & 0xFF)); return hex.toString(); }
Thread Reply