本文整理汇总了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);
}
示例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));
}
示例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)));
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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));
}
示例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));
}
示例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);
}