how to generate base64 string by normal string.

Report
Question
577 views

Use this 2 Function to get your result.

Please explain why do you think this question should be reported?

Report Cancel

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

Leave an comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>