Tomcat jdbcrealmのダイジェストパスワードを準備する方法
質問
例: http://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html#jdbcrealm user_pass
列のタイプはvarchar(15)
です。Tomcat?が予想されるMD5ダイジェストに変換するには、パスワードjava.security.MessageDigest
(たとえばMD5ダイジェストに変換する必要があります。
ps。
私は次のことを試してみました、そしてそれはうまくいきます(digest.bat結果と一致させる)。唯一の質問は今の長さです。ダイジェストは15文字より長いです。テーブルを変更するだけですか?
public class DigestRunner {
/**
* @param args
* @throws NoSuchAlgorithmException
*/
public static void main(String[] args) throws NoSuchAlgorithmException {
String password = "abcd";
MessageDigest dig = MessageDigest.getInstance("MD5");
System.out.println(toString(dig.digest(password.getBytes())));
}
public static String toString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.length * 2);
for(byte b : ba)
hex.append(String.format("%02x", b));
return hex.toString();
}
}
. 解決
varchar(15)
is definitely too short for digest password but it's usually enough for plaintext passwords. Just increase the size.
I have used the following code for creating digest passwords:
final MessageDigest messageDigest = java.security.MessageDigest.
getInstance("SHA-256");
final byte bin[] = messageDigest.digest(("admin").getBytes());
System.out.println(Base64.encodeBase64String(bin));
(Base64
from Apache Commons Codec)
Furthermore, there is a digest.bat
/digest.sh
in Tomcat, check it on the page that you linked.
所属していません StackOverflow