当前位置: 首页>>代码示例>>Java>>正文


Java Hex类代码示例

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


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

示例1: computeCramMd5Bytes

import com.fsck.k9.mail.filter.Hex; //导入依赖的package包/类
/**
 * Computes the response for CRAM-MD5 authentication mechanism given the user credentials and
 * the server-provided nonce.
 *
 * @param username The username.
 * @param password The password.
 * @param b64Nonce The nonce as base64-encoded byte array.
 * @return The CRAM-MD5 response as byte array.
 *
 * @throws MessagingException If something went wrong.
 *
 * @see <a href="https://tools.ietf.org/html/rfc2195">RFC 2195</a>
 */
public static byte[] computeCramMd5Bytes(String username, String password, byte[] b64Nonce)
throws MessagingException {

    try {
        byte[] nonce = Base64.decodeBase64(b64Nonce);

        byte[] secretBytes = password.getBytes();
        MessageDigest md = MessageDigest.getInstance("MD5");
        if (secretBytes.length > 64) {
            secretBytes = md.digest(secretBytes);
        }

        byte[] ipad = new byte[64];
        byte[] opad = new byte[64];
        System.arraycopy(secretBytes, 0, ipad, 0, secretBytes.length);
        System.arraycopy(secretBytes, 0, opad, 0, secretBytes.length);
        for (int i = 0; i < ipad.length; i++) ipad[i] ^= 0x36;
        for (int i = 0; i < opad.length; i++) opad[i] ^= 0x5c;

        md.update(ipad);
        byte[] firstPass = md.digest(nonce);

        md.update(opad);
        byte[] result = md.digest(firstPass);

        String plainCRAM = username + " " + Hex.encodeHex(result);
        byte[] b64CRAM = Base64.encodeBase64(plainCRAM.getBytes());

        return b64CRAM;

    } catch (Exception e) {
        throw new MessagingException("Something went wrong during CRAM-MD5 computation", e);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:48,代码来源:Authentication.java

示例2: computeCramMd5Bytes

import com.fsck.k9.mail.filter.Hex; //导入依赖的package包/类
/**
 * Computes the response for CRAM-MD5 authentication mechanism given the user credentials and
 * the server-provided nonce.
 *
 * @param username The username.
 * @param password The password.
 * @param b64Nonce The nonce as base64-encoded byte array.
 * @return The CRAM-MD5 response as byte array.
 *
 * @throws MessagingException If something went wrong.
 *
 * @see <a href="https://tools.ietf.org/html/rfc2195">RFC 2195</a>
 */
public static byte[] computeCramMd5Bytes(String username, String password, byte[] b64Nonce)
throws MessagingException {

    try {
        byte[] nonce = Base64.decodeBase64(b64Nonce);

        byte[] secretBytes = password.getBytes();
        MessageDigest md = MessageDigest.getInstance("MD5");
        if (secretBytes.length > 64) {
            secretBytes = md.digest(secretBytes);
        }

        byte[] ipad = new byte[64];
        byte[] opad = new byte[64];
        System.arraycopy(secretBytes, 0, ipad, 0, secretBytes.length);
        System.arraycopy(secretBytes, 0, opad, 0, secretBytes.length);
        for (int i = 0; i < ipad.length; i++) ipad[i] ^= 0x36;
        for (int i = 0; i < opad.length; i++) opad[i] ^= 0x5c;

        md.update(ipad);
        byte[] firstPass = md.digest(nonce);

        md.update(opad);
        byte[] result = md.digest(firstPass);

        String plainCRAM = username + " " + new String(Hex.encodeHex(result));
        byte[] b64CRAM = Base64.encodeBase64(plainCRAM.getBytes());

        return b64CRAM;

    } catch (Exception e) {
        throw new MessagingException("Something went wrong during CRAM-MD5 computation", e);
    }
}
 
开发者ID:scoute-dich,项目名称:K9-MailClient,代码行数:48,代码来源:Authentication.java

示例3: computeCramMd5Bytes

import com.fsck.k9.mail.filter.Hex; //导入依赖的package包/类
/**
 * Computes the response for CRAM-MD5 authentication mechanism given the user credentials and
 * the server-provided nonce.
 *
 * @param username The username.
 * @param password The password.
 * @param b64Nonce The nonce as base64-encoded byte array.
 * @return The CRAM-MD5 response as byte array.
 *
 * @throws AuthenticationFailedException If something went wrong.
 *
 * @see <a href="https://tools.ietf.org/html/rfc2195">RFC 2195</a>
 */
public static byte[] computeCramMd5Bytes(String username, String password, byte[] b64Nonce)
throws AuthenticationFailedException {

    try {
        byte[] nonce = Base64.decodeBase64(b64Nonce);

        byte[] secretBytes = password.getBytes(US_ASCII);
        MessageDigest md = MessageDigest.getInstance("MD5");
        if (secretBytes.length > 64) {
            secretBytes = md.digest(secretBytes);
        }

        byte[] ipad = new byte[64];
        byte[] opad = new byte[64];
        System.arraycopy(secretBytes, 0, ipad, 0, secretBytes.length);
        System.arraycopy(secretBytes, 0, opad, 0, secretBytes.length);
        for (int i = 0; i < ipad.length; i++) ipad[i] ^= 0x36;
        for (int i = 0; i < opad.length; i++) opad[i] ^= 0x5c;

        md.update(ipad);
        byte[] firstPass = md.digest(nonce);

        md.update(opad);
        byte[] result = md.digest(firstPass);

        String plainCRAM = username + " " + new String(Hex.encodeHex(result));
        byte[] b64CRAM = Base64.encodeBase64(plainCRAM.getBytes(US_ASCII));

        return b64CRAM;

    } catch (Exception e) {
        throw new AuthenticationFailedException("Something went wrong during CRAM-MD5 computation", e);
    }
}
 
开发者ID:masenov,项目名称:k-9-master,代码行数:48,代码来源:Authentication.java


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