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


Java MessageDigestAlgorithms类代码示例

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


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

示例1: generateAccessTokenHash

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
private String generateAccessTokenHash(final AccessToken accessTokenId,
                                       final OidcRegisteredService service) {
    final byte[] tokenBytes = accessTokenId.getId().getBytes();
    final String hashAlg;

    switch (signingService.getJsonWebKeySigningAlgorithm()) {
        case AlgorithmIdentifiers.RSA_USING_SHA512:
            hashAlg = MessageDigestAlgorithms.SHA_512;
            break;
        case AlgorithmIdentifiers.RSA_USING_SHA256:
        default:
            hashAlg = MessageDigestAlgorithms.SHA_256;
    }

    LOGGER.debug("Digesting access token hash via algorithm [{}]", hashAlg);
    final byte[] digested = DigestUtils.rawDigest(hashAlg, tokenBytes);
    final byte[] hashBytesLeftHalf = Arrays.copyOf(digested, digested.length / 2);
    return EncodingUtils.encodeBase64(hashBytesLeftHalf);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:OidcIdTokenGeneratorService.java

示例2: main

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

      
      MessageDigest md = MessageDigest.getInstance(MessageDigestAlgorithms.MD5);
      md.update("texto a cifrar".getBytes());
      byte[] digest = md.digest();

      // Se escribe byte a byte en hexadecimal
      for (byte b : digest) {
         System.out.print(Integer.toHexString(0xFF & b));
      }
      System.out.println();

      // Se escribe codificado base 64. Se necesita la librer�a
      // commons-codec-x.x.x.jar de Apache
      byte[] encoded = Base64.encodeBase64(digest);
      System.out.println(new String(encoded));
   }
 
开发者ID:chuidiang,项目名称:chuidiang-ejemplos,代码行数:19,代码来源:MD5Example.java

示例3: run

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
private void run() throws IOException {
    if (algorithm.equalsIgnoreCase("ALL") || algorithm.equals("*")) {
        run(MessageDigestAlgorithms.values());
        return;
    }
    final MessageDigest messageDigest = DigestUtils.getDigest(algorithm, null);
    if (messageDigest != null) {
        run("", messageDigest);
    } else {
        run("", DigestUtils.getDigest(algorithm.toUpperCase(Locale.ROOT)));
    }
}
 
开发者ID:HTBridge,项目名称:pivaa,代码行数:13,代码来源:Digest.java

示例4: hash

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
/**
 * The hashing function used by the Cache.
 * 
 * @param key
 * @return
 * @throws VictimsException
 */
protected String hash(String key) throws VictimsException {
    try {
        MessageDigest mda = MessageDigest
                .getInstance(MessageDigestAlgorithms.SHA_256);
        return Hex.encodeHexString(mda.digest(key.getBytes()));
    } catch (NoSuchAlgorithmException e) {
        throw new VictimsException(String.format("Could not hash key: %s",
                key), e);
    }
}
 
开发者ID:victims,项目名称:victims-lib-java,代码行数:18,代码来源:VictimsResultCache.java

示例5: hashFile

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
/**
 * Hash the file to get a "unique" key for caching
 * 
 * @param file
 *            file to hash
 * @param name
 *            canonical file name
 * @return name + md5 hash of file
 * @throws VictimsException
 */
private static String hashFile(File file, String name)
		throws VictimsException {
	InputStream fis = null;
	try {
		fis = new FileInputStream(file);
		byte[] buffer = new byte[1024];

		MessageDigest mda = MessageDigest
				.getInstance(MessageDigestAlgorithms.MD5);
		int numRead;
		do {
			numRead = fis.read(buffer);
			if (numRead > 0) {
				mda.update(buffer, 0, numRead);
			}
		} while (numRead != -1);
		return name + Hex.encodeHexString(mda.digest());

	} catch (NoSuchAlgorithmException e) {
		throw new VictimsException(String.format("Could not hash file: %s",
				name), e);
	} catch (IOException io) {
		throw new VictimsException(String.format("Could not open file: %s",
				name), io);
	} finally {
		IOUtils.closeQuietly(fis);
	}
}
 
开发者ID:victims,项目名称:victims-plugin-eclipse-legacy,代码行数:39,代码来源:FileStub.java

示例6: hashFile

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
/**
 * Hash the file to get a "unique" key for caching
 * 
 * @param file
 *            file to hash
 * @param name
 *            canonical file name
 * @return name + md5 hash of file
 * @throws VictimsException
 */
private static String hashFile(File file, String name)
		throws VictimsException {
	InputStream fis = null;
	try {
		fis = new FileInputStream(file);
		byte[] buffer = new byte[1024];

		MessageDigest mda = MessageDigest
				.getInstance(MessageDigestAlgorithms.MD5);
		int numRead;
		do {
			numRead = fis.read(buffer);
			if (numRead > 0) {
				mda.update(buffer, 0, numRead);
			}
		} while (numRead != -1);

		return name + Hex.encodeHexString(mda.digest());

	} catch (NoSuchAlgorithmException e) {
		throw new VictimsException(String.format("Could not hash file: %s",
				name), e);
	} catch (IOException io) {
		throw new VictimsException(String.format("Could not open file: %s",
				name), io);
	} finally {
		IOUtils.closeQuietly(fis);
	}
}
 
开发者ID:victims,项目名称:victims-plugin-ant-legacy,代码行数:40,代码来源:FileStub.java

示例7: sha1

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
private static byte[] sha1(String s) throws NoSuchAlgorithmException {
   	MessageDigest SHA1 = MessageDigest.getInstance(MessageDigestAlgorithms.SHA_1);
	SHA1.reset();
	SHA1.update(s.getBytes());
	return SHA1.digest();
}
 
开发者ID:fpompermaier,项目名称:onvif,代码行数:7,代码来源:SimpleSecurityHandler.java

示例8: sha512

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
/**
 * Computes hex encoded SHA512 digest.
 *
 * @param data data to be hashed
 * @return sha-512 hash
 */
public static String sha512(final String data) {
    return digest(MessageDigestAlgorithms.SHA_512, data.getBytes(StandardCharsets.UTF_8));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:10,代码来源:DigestUtils.java

示例9: sha256

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
/**
 * Computes hex encoded SHA256 digest.
 *
 * @param data data to be hashed
 * @return sha-256 hash
 */
public static String sha256(final String data) {
    return digest(MessageDigestAlgorithms.SHA_256, data.getBytes(StandardCharsets.UTF_8));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:10,代码来源:DigestUtils.java

示例10: sha

import org.apache.commons.codec.digest.MessageDigestAlgorithms; //导入依赖的package包/类
/**
 * Computes hex encoded SHA digest.
 *
 * @param data data to be hashed
 * @return sha hash
 */
public static String sha(final String data) {
    return digest(MessageDigestAlgorithms.SHA_1, data);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:10,代码来源:DigestUtils.java


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