LoginSignup
9
6

More than 5 years have passed since last update.

文字列のハッシュ値を取得

Last updated at Posted at 2014-07-23
String source = "source string";

try {
    MessageDigest md = MessageDigest.getInstance("SHA-512");
    md.update(source.getBytes());
    byte[] hash = md.digest();
    StringBuilder sb = new StringBuilder();
    for (byte b : hash) {
        sb.append(String.format("%02x", b));
    }
} catch (NoSuchAlgorithmException e) {
    System.out.printf(
        "Exception: %s, Source string: %s",
        e.getMessage(),
        source);
}

標準アルゴリズム名のドキュメント

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6