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

Java MD5Encoder类代码示例

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

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



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

示例1: generateNonce

import org.apache.catalina.util.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:deathspeeder,项目名称:class-guard,代码行数:34,代码来源:DigestAuthenticator.java


示例2: authenticate

import org.apache.catalina.util.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:deathspeeder,项目名称:class-guard,代码行数:13,代码来源:DigestAuthenticator.java


示例3: getDigest

import org.apache.catalina.util.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:deathspeeder,项目名称:class-guard,代码行数:38,代码来源:RealmBase.java


示例4: buildDigestResponse

import org.apache.catalina.util.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:deathspeeder,项目名称:class-guard,代码行数:37,代码来源:TesterDigestAuthenticatorPerformance.java


示例5: TesterRunnable

import org.apache.catalina.util.MD5Encoder; //导入依赖的package包/类
public TesterRunnable(int id, int requestCount) throws Exception {
    this.requestCount = requestCount;

    path = "http://localhost:" + getPort() + CONTEXT_PATH + URI;

    // Make the first request as we need the Digest challenge to obtain
    // the server nonce
    Map<String,List<String>> respHeaders =
            new HashMap<String,List<String>>();
    getUrl(path, new ByteChunk(), respHeaders);
    
    nonce = TestDigestAuthenticator.getNonce(respHeaders);
    opaque = TestDigestAuthenticator.getOpaque(respHeaders);
    
    cnonce = "cnonce" + id;

    reqHeaders = new  HashMap<String,List<String>>();
    authHeader = new ArrayList<String>();
    reqHeaders.put(CLIENT_AUTH_HEADER, authHeader);
    
    digester = MessageDigest.getInstance("MD5");
    encoder = new MD5Encoder();

    String a1 = USER + ":" + REALM + ":" + PWD;
    String a2 = "GET:" + CONTEXT_PATH + URI;
    
    md5a1 = encoder.encode(digester.digest(a1.getBytes()));
    md5a2 = encoder.encode(digester.digest(a2.getBytes()));
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:30,代码来源:TesterDigestAuthenticatorPerformance.java


示例6: digest

import org.apache.catalina.util.MD5Encoder; //导入依赖的package包/类
private static String digest(String input) throws NoSuchAlgorithmException {
    // This is slow but should be OK as this is only a test
    MessageDigest md5 = MessageDigest.getInstance("MD5");
    MD5Encoder encoder = new MD5Encoder();

    md5.update(input.getBytes());
    return encoder.encode(md5.digest());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:9,代码来源:TestDigestAuthenticator.java


示例7: authenticate

import org.apache.catalina.util.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:deathspeeder,项目名称:class-guard,代码行数:61,代码来源:RealmBase.java


示例8: digest

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java SparseSequence类代码示例发布时间:2022-05-22
下一篇:
Java ListAdapteeCollection类代码示例发布时间: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