jp.terasoluna.fw.util
クラス HashUtil

java.lang.Object
  上位を拡張 jp.terasoluna.fw.util.HashUtil

public class HashUtil
extends Object

ハッシュ値を計算するユーティリティクラス。

java.security.MessageDigestを用いて、文字列のハッシュ値を 取得する。
MD5、SHA1、その他アルゴリズムを使用して取得する。 使用例

   ・・・
    // DBに登録するユーザパスワードのハッシュ値を計算する。
    byte[] hash = HashUtil.hashMD5(userPassword);
   ・・・
  


コンストラクタの概要
HashUtil()
           
 
メソッドの概要
static byte[] hash(String algorithm, String str)
          指定されたアルゴリズムで文字列をハッシュ値を取得する。
static byte[] hashMD5(String str)
          MD5アルゴリズムで文字列のハッシュ値を取得する。
static byte[] hashSHA1(String str)
          SHA1アルゴリズムで文字列のハッシュ値を取得する。
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

コンストラクタの詳細

HashUtil

public HashUtil()
メソッドの詳細

hash

public static byte[] hash(String algorithm,
                          String str)
                   throws NoSuchAlgorithmException
指定されたアルゴリズムで文字列をハッシュ値を取得する。

パラメータ:
algorithm - ハッシュアルゴリズム
str - ハッシュ値の取得対象の文字列
戻り値:
ハッシュ値
例外:
NoSuchAlgorithmException - ハッシュアルゴリズムが不正なとき

hashMD5

public static byte[] hashMD5(String str)
MD5アルゴリズムで文字列のハッシュ値を取得する。

パラメータ:
str - ハッシュ値の取得対象の文字列
戻り値:
ハッシュ値

hashSHA1

public static byte[] hashSHA1(String str)
SHA1アルゴリズムで文字列のハッシュ値を取得する。

パラメータ:
str - ハッシュ値の取得対象の文字列
戻り値:
ハッシュ値


Copyright © 2011. All Rights Reserved.