To calculate the digested value of a cleartext password, two convenience techniques are supported:
If you are writing an application that needs to calculate digested passwords dynamically, call the static Digest()method of the org.apache.catalina.realm.RealmBase class, passing the cleartext password and the digest algorithm name as arguments. This method will return the digested password.
If you want to execute a command line utility to calculate the digested password, simply execute
<code>CATALINA_HOME/bin/digest. -a {algorithm} {cleartext-password} </code>
and the digested version of this cleartext password will be returned to standard output.
方式一:用代码来生成:
import org.apache.catalina.realm.RealmBase;
public class T {
public static void main(String[] args) {
//参数1:要加密的字符串;参数2:加密算法;参数3:字符串的编码
String base = RealmBase.Digest("alvis:MyConstraints:pwd", "MD5", null);
System.out.println(base);
}
}
If using digested passwords with DIGEST authentication, the cleartext used to generate the digest is different and the digest must use the MD5 algorithm. In the examples above {cleartext-password} must be replaced with {username}:{realm}:{cleartext-password}. For example, in a development environment this might take the form testUser:Authentication required:testPassword. The value for {realm} is taken from the <realm-name> element of the web application’s <login-config>. If not specified in web.xml, the default value of Authentication required is used.