• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MD5Encoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.tomcat.util.security.MD5Encoder的典型用法代码示例。如果您正苦于以下问题:Java MD5Encoder类的具体用法?Java MD5Encoder怎么用?Java MD5Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MD5Encoder类属于org.apache.tomcat.util.security包,在下文中一共展示了MD5Encoder类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generateNonce

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Generate a unique token. The token is generated according to the
 * following pattern. NOnceToken = Base64 ( MD5 ( client-IP ":" time-stamp
 * ":" private-key ) ).
 *
 * @param request
 *            HTTP Servlet request
 */
protected String generateNonce(Request request) {

	long currentTime = System.currentTimeMillis();

	synchronized (lastTimestampLock) {
		if (currentTime > lastTimestamp) {
			lastTimestamp = currentTime;
		} else {
			currentTime = ++lastTimestamp;
		}
	}

	String ipTimeKey = request.getRemoteAddr() + ":" + currentTime + ":" + getKey();

	byte[] buffer = ConcurrentMessageDigest.digestMD5(ipTimeKey.getBytes(B2CConverter.ISO_8859_1));
	String nonce = currentTime + ":" + MD5Encoder.encode(buffer);

	NonceInfo info = new NonceInfo(currentTime, getNonceCountWindowSize());
	synchronized (nonces) {
		nonces.put(nonce, info);
	}

	return nonce;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:33,代码来源:DigestAuthenticator.java


示例2: testAuthenticateWithUserPassword

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
@Test
public void testAuthenticateWithUserPassword() throws Exception {
    // GIVEN
    JNDIRealm realm = buildRealm(PASSWORD, null);
    realm.setUserPassword(USER_PASSWORD_ATTR);

    // WHEN
    String expectedResponse =
            MD5Encoder.encode(md5Helper.digest((ha1() + ":" + NONCE + ":" + HA2).getBytes()));
    Principal principal =
            realm.authenticate(USER, expectedResponse, NONCE, null, null, null, REALM, HA2);

    // THEN
    Assert.assertTrue(principal instanceof GenericPrincipal);
    Assert.assertEquals(PASSWORD, ((GenericPrincipal)principal).getPassword());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:TestJNDIRealm.java


示例3: testAuthenticateWithUserPasswordAndDigest

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
@Test
public void testAuthenticateWithUserPasswordAndDigest() throws Exception {
    // GIVEN
    JNDIRealm realm = buildRealm(ha1(), "MD5");
    realm.setUserPassword(USER_PASSWORD_ATTR);

    // WHEN
    String expectedResponse =
            MD5Encoder.encode(md5Helper.digest((ha1() + ":" + NONCE + ":" + HA2).getBytes()));
    Principal principal =
            realm.authenticate(USER, expectedResponse, NONCE, null, null, null, REALM, HA2);

    // THEN
    Assert.assertTrue(principal instanceof GenericPrincipal);
    Assert.assertEquals(ha1(), ((GenericPrincipal)principal).getPassword());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:TestJNDIRealm.java


示例4: generateNonce

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Generate a unique token. The token is generated according to the
 * following pattern. NOnceToken = Base64 ( MD5 ( client-IP ":"
 * time-stamp ":" private-key ) ).
 *
 * @param request HTTP Servlet request
 */
protected String generateNonce(Request request) {

    long currentTime = System.currentTimeMillis();

    synchronized (lastTimestampLock) {
        if (currentTime > lastTimestamp) {
            lastTimestamp = currentTime;
        } else {
            currentTime = ++lastTimestamp;
        }
    }

    String ipTimeKey =
        request.getRemoteAddr() + ":" + currentTime + ":" + getKey();

    byte[] buffer = ConcurrentMessageDigest.digestMD5(
            ipTimeKey.getBytes(B2CConverter.ISO_8859_1));
    String nonce = currentTime + ":" + MD5Encoder.encode(buffer);

    NonceInfo info = new NonceInfo(currentTime, getNonceCountWindowSize());
    synchronized (nonces) {
        nonces.put(nonce, info);
    }

    return nonce;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:34,代码来源:DigestAuthenticator.java


示例5: authenticate

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
public Principal authenticate(Realm realm) {
    // Second MD5 digest used to calculate the digest :
    // MD5(Method + ":" + uri)
    String a2 = method + ":" + uri;

    byte[] buffer = ConcurrentMessageDigest.digestMD5(
            a2.getBytes(B2CConverter.ISO_8859_1));
    String md5a2 = MD5Encoder.encode(buffer);

    return realm.authenticate(userName, response, nonce, nc, cnonce,
            qop, realmName, md5a2);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:13,代码来源:DigestAuthenticator.java


示例6: getDigest

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Return the digest associated with given principal's user name.
 */
protected String getDigest(String username, String realmName) {
    if (md5Helper == null) {
        try {
            md5Helper = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            log.error("Couldn't get MD5 digest: ", e);
            throw new IllegalStateException(e.getMessage());
        }
    }

    if (hasMessageDigest()) {
        // Use pre-generated digest
        return getPassword(username);
    }

    String digestValue = username + ":" + realmName + ":"
        + getPassword(username);

    byte[] valueBytes = null;
    try {
        valueBytes = digestValue.getBytes(getDigestCharset());
    } catch (UnsupportedEncodingException uee) {
        log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
        throw new IllegalArgumentException(uee.getMessage());
    }

    byte[] digest = null;
    // Bugzilla 32137
    synchronized(md5Helper) {
        digest = md5Helper.digest(valueBytes);
    }

    return MD5Encoder.encode(digest);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:38,代码来源:RealmBase.java


示例7: buildDigestResponse

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
private String buildDigestResponse(String nonce) {

            String ncString = String.format("%1$08x",
                    Integer.valueOf(nonceCount.incrementAndGet()));
            String cnonce = "cnonce";

            String response = MD5A1 + ":" + nonce + ":" + ncString + ":" +
                    cnonce + ":" + QOP + ":" + MD5A2;

            String md5response = MD5Encoder.encode(
                    ConcurrentMessageDigest.digest("MD5", response.getBytes()));

            StringBuilder auth = new StringBuilder();
            auth.append("Digest username=\"");
            auth.append(USER);
            auth.append("\", realm=\"");
            auth.append(REALM);
            auth.append("\", nonce=\"");
            auth.append(nonce);
            auth.append("\", uri=\"");
            auth.append(CONTEXT_PATH + URI);
            auth.append("\", opaque=\"");
            auth.append(authenticator.getOpaque());
            auth.append("\", response=\"");
            auth.append(md5response);
            auth.append("\"");
            auth.append(", qop=");
            auth.append(QOP);
            auth.append(", nc=");
            auth.append(ncString);
            auth.append(", cnonce=\"");
            auth.append(cnonce);
            auth.append("\"");

            return auth.toString();
        }
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:37,代码来源:TesterDigestAuthenticatorPerformance.java


示例8: testAuthenticateWithoutUserPassword

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
@Test
public void testAuthenticateWithoutUserPassword() throws Exception {
    // GIVEN
    JNDIRealm realm = buildRealm(PASSWORD, null);

    // WHEN
    String expectedResponse =
            MD5Encoder.encode(md5Helper.digest((ha1() + ":" + NONCE + ":" + HA2).getBytes()));
    Principal principal =
            realm.authenticate(USER, expectedResponse, NONCE, null, null, null, REALM, HA2);

    // THEN
    Assert.assertNull(principal);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:15,代码来源:TestJNDIRealm.java


示例9: authenticate

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
public Principal authenticate(Realm realm) {
	// Second MD5 digest used to calculate the digest :
	// MD5(Method + ":" + uri)
	String a2 = method + ":" + uri;

	byte[] buffer = ConcurrentMessageDigest.digestMD5(a2.getBytes(B2CConverter.ISO_8859_1));
	String md5a2 = MD5Encoder.encode(buffer);

	return realm.authenticate(userName, response, nonce, nc, cnonce, qop, realmName, md5a2);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:11,代码来源:DigestAuthenticator.java


示例10: getDigest

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Return the digest associated with given principal's user name.
 */
protected String getDigest(String username, String realmName) {
	if (md5Helper == null) {
		try {
			md5Helper = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			log.error("Couldn't get MD5 digest: ", e);
			throw new IllegalStateException(e.getMessage());
		}
	}

	if (hasMessageDigest()) {
		// Use pre-generated digest
		return getPassword(username);
	}

	String digestValue = username + ":" + realmName + ":" + getPassword(username);

	byte[] valueBytes = null;
	try {
		valueBytes = digestValue.getBytes(getDigestCharset());
	} catch (UnsupportedEncodingException uee) {
		log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
		throw new IllegalArgumentException(uee.getMessage());
	}

	byte[] digest = null;
	// Bugzilla 32137
	synchronized (md5Helper) {
		digest = md5Helper.digest(valueBytes);
	}

	return MD5Encoder.encode(digest);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:37,代码来源:RealmBase.java


示例11: getDigest

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Return the digest associated with given principal's user name.
 */
protected String getDigest(String username, String realmName) {
    if (md5Helper == null) {
        try {
            md5Helper = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            log.error("Couldn't get MD5 digest: ", e);
            throw new IllegalStateException(e.getMessage());
        }
    }

    if (hasMessageDigest()) {
        // Use pre-generated digest
        return getPassword(username);
    }
        
    String digestValue = username + ":" + realmName + ":"
        + getPassword(username);

    byte[] valueBytes = null;
    try {
        valueBytes = digestValue.getBytes(getDigestCharset());
    } catch (UnsupportedEncodingException uee) {
        log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
        throw new IllegalArgumentException(uee.getMessage());
    }

    byte[] digest = null;
    // Bugzilla 32137
    synchronized(md5Helper) {
        digest = md5Helper.digest(valueBytes);
    }

    return MD5Encoder.encode(digest);
}
 
开发者ID:sdw2330976,项目名称:apache-tomcat-7.0.57,代码行数:38,代码来源:RealmBase.java


示例12: authenticate

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Return the Principal associated with the specified username, which
 * matches the digest calculated using the given parameters using the
 * method described in RFC 2069; otherwise return <code>null</code>.
 *
 * @param username Username of the Principal to look up
 * @param clientDigest Digest which has been submitted by the client
 * @param nonce Unique (or supposedly unique) token which has been used
 * for this request
 * @param realm Realm name
 * @param md5a2 Second MD5 digest used to calculate the digest :
 * MD5(Method + ":" + uri)
 */
@Override
public Principal authenticate(String username, String clientDigest,
                              String nonce, String nc, String cnonce,
                              String qop, String realm,
                              String md5a2) {

    // In digest auth, digests are always lower case
    String md5a1 = getDigest(username, realm);
    if (md5a1 == null)
        return null;
    md5a1 = md5a1.toLowerCase(Locale.ENGLISH);
    String serverDigestValue;
    if (qop == null) {
        serverDigestValue = md5a1 + ":" + nonce + ":" + md5a2;
    } else {
        serverDigestValue = md5a1 + ":" + nonce + ":" + nc + ":" +
                cnonce + ":" + qop + ":" + md5a2;
    }

    byte[] valueBytes = null;
    try {
        valueBytes = serverDigestValue.getBytes(getDigestCharset());
    } catch (UnsupportedEncodingException uee) {
        log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
        throw new IllegalArgumentException(uee.getMessage());
    }

    String serverDigest = null;
    // Bugzilla 32137
    synchronized(md5Helper) {
        serverDigest = MD5Encoder.encode(md5Helper.digest(valueBytes));
    }

    if (log.isDebugEnabled()) {
        log.debug("Digest : " + clientDigest + " Username:" + username
                + " ClientSigest:" + clientDigest + " nonce:" + nonce
                + " nc:" + nc + " cnonce:" + cnonce + " qop:" + qop
                + " realm:" + realm + "md5a2:" + md5a2
                + " Server digest:" + serverDigest);
    }

    if (serverDigest.equals(clientDigest)) {
        return getPrincipal(username);
    }

    return null;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:61,代码来源:RealmBase.java


示例13: digest

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
private static String digest(String input) {
    return MD5Encoder.encode(
            ConcurrentMessageDigest.digestMD5(input.getBytes()));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:5,代码来源:TestSSOnonLoginAndDigestAuthenticator.java


示例14: ha1

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
private String ha1() {
    String a1 = USER + ":" + REALM + ":" + PASSWORD;
    return MD5Encoder.encode(md5Helper.digest(a1.getBytes()));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:5,代码来源:TestJNDIRealm.java


示例15: authenticate

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Return the Principal associated with the specified username, which
 * matches the digest calculated using the given parameters using the method
 * described in RFC 2069; otherwise return <code>null</code>.
 *
 * @param username
 *            Username of the Principal to look up
 * @param clientDigest
 *            Digest which has been submitted by the client
 * @param nonce
 *            Unique (or supposedly unique) token which has been used for
 *            this request
 * @param realm
 *            Realm name
 * @param md5a2
 *            Second MD5 digest used to calculate the digest : MD5(Method +
 *            ":" + uri)
 */
@Override
public Principal authenticate(String username, String clientDigest, String nonce, String nc, String cnonce,
		String qop, String realm, String md5a2) {

	// In digest auth, digests are always lower case
	String md5a1 = getDigest(username, realm);
	if (md5a1 == null)
		return null;
	md5a1 = md5a1.toLowerCase(Locale.ENGLISH);
	String serverDigestValue;
	if (qop == null) {
		serverDigestValue = md5a1 + ":" + nonce + ":" + md5a2;
	} else {
		serverDigestValue = md5a1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + md5a2;
	}

	byte[] valueBytes = null;
	try {
		valueBytes = serverDigestValue.getBytes(getDigestCharset());
	} catch (UnsupportedEncodingException uee) {
		log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
		throw new IllegalArgumentException(uee.getMessage());
	}

	String serverDigest = null;
	// Bugzilla 32137
	synchronized (md5Helper) {
		serverDigest = MD5Encoder.encode(md5Helper.digest(valueBytes));
	}

	if (log.isDebugEnabled()) {
		log.debug("Digest : " + clientDigest + " Username:" + username + " ClientDigest:" + clientDigest + " nonce:"
				+ nonce + " nc:" + nc + " cnonce:" + cnonce + " qop:" + qop + " realm:" + realm + "md5a2:" + md5a2
				+ " Server digest:" + serverDigest);
	}

	if (serverDigest.equals(clientDigest)) {
		return getPrincipal(username);
	}

	return null;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:61,代码来源:RealmBase.java


示例16: authenticate

import org.apache.tomcat.util.security.MD5Encoder; //导入依赖的package包/类
/**
 * Return the Principal associated with the specified username, which
 * matches the digest calculated using the given parameters using the
 * method described in RFC 2069; otherwise return <code>null</code>.
 *
 * @param username Username of the Principal to look up
 * @param clientDigest Digest which has been submitted by the client
 * @param nonce Unique (or supposedly unique) token which has been used
 * for this request
 * @param realm Realm name
 * @param md5a2 Second MD5 digest used to calculate the digest :
 * MD5(Method + ":" + uri)
 */
@Override
public Principal authenticate(String username, String clientDigest,
                              String nonce, String nc, String cnonce,
                              String qop, String realm,
                              String md5a2) {

    // In digest auth, digests are always lower case
    String md5a1 = getDigest(username, realm);
    if (md5a1 == null)
        return null;
    md5a1 = md5a1.toLowerCase(Locale.ENGLISH);
    String serverDigestValue;
    if (qop == null) {
        serverDigestValue = md5a1 + ":" + nonce + ":" + md5a2;
    } else {
        serverDigestValue = md5a1 + ":" + nonce + ":" + nc + ":" +
                cnonce + ":" + qop + ":" + md5a2;
    }

    byte[] valueBytes = null;
    try {
        valueBytes = serverDigestValue.getBytes(getDigestCharset());
    } catch (UnsupportedEncodingException uee) {
        log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
        throw new IllegalArgumentException(uee.getMessage());
    }

    String serverDigest = null;
    // Bugzilla 32137
    synchronized(md5Helper) {
        serverDigest = MD5Encoder.encode(md5Helper.digest(valueBytes));
    }

    if (log.isDebugEnabled()) {
        log.debug("Digest : " + clientDigest + " Username:" + username 
                + " ClientSigest:" + clientDigest + " nonce:" + nonce 
                + " nc:" + nc + " cnonce:" + cnonce + " qop:" + qop 
                + " realm:" + realm + "md5a2:" + md5a2 
                + " Server digest:" + serverDigest);
    }
    
    if (serverDigest.equals(clientDigest)) {
        return getPrincipal(username);
    }

    return null;
}
 
开发者ID:sdw2330976,项目名称:apache-tomcat-7.0.57,代码行数:61,代码来源:RealmBase.java



注:本文中的org.apache.tomcat.util.security.MD5Encoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RangeDifference类代码示例发布时间:2022-05-22
下一篇:
Java GenLayerHills类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap