DigestUtils
来源:互联网 发布:普通增值税发票软件 编辑:程序博客网 时间:2024/06/06 05:46
- /*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org1.apache.commons.codec.digest;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import org1.apache.commons.codec.binary.Hex;
- /**
- * Operations to simplifiy common {@link java.security.MessageDigest} tasks. This
- * class is thread safe.
- *
- * @author Apache Software Foundation
- */
- public class DigestUtils{
- /**
- * Returns a MessageDigest for the given <code>algorithm</code>.
- *
- * @param algorithm The MessageDigest algorithm name.
- * @return An MD5 digest instance.
- * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,
- */
- static MessageDigest getDigest(String algorithm){
- try {
- return MessageDigest.getInstance(algorithm);
- } catch (NoSuchAlgorithmException e){
- throw newRuntimeException(e.getMessage());
- }
- }
- /**
- * Returns an MD5 MessageDigest.
- *
- * @return An MD5 digest instance.
- * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,
- */
- private staticMessageDigest getMd5Digest(){
- return getDigest("MD5");
- }
- /**
- * Returns an SHA digest.
- *
- * @return An SHA digest instance.
- * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,
- */
- private staticMessageDigest getShaDigest(){
- return getDigest("SHA");
- }
- /**
- * Calculates the MD5 digest and returns the value as a 16 element
- * <code>byte[]</code>.
- *
- * @param data Data to digest
- * @return MD5 digest
- */
- public staticbyte[] md5(byte[] data) {
- return getMd5Digest().digest(data);
- }
- /**
- * Calculates the MD5 digest and returns the value as a 16 element
- * <code>byte[]</code>.
- *
- * @param data Data to digest
- * @return MD5 digest
- */
- public staticbyte[] md5(String data){
- return md5(data.getBytes());
- }
- /**
- * Calculates the MD5 digest and returns the value as a 32 character
- * hex string.
- *
- * @param data Data to digest
- * @return MD5 digest as a hex string
- */
- public staticString md5Hex(byte[] data){
- return newString(Hex.encodeHex(md5(data)));
- }
- /**
- * Calculates the MD5 digest and returns the value as a 32 character
- * hex string.
- *
- * @param data Data to digest
- * @return MD5 digest as a hex string
- */
- public staticString md5Hex(String data){
- return newString(Hex.encodeHex(md5(data)));
- }
- /**
- * Calculates the SHA digest and returns the value as a
- * <code>byte[]</code>.
- *
- * @param data Data to digest
- * @return SHA digest
- */
- public staticbyte[] sha(byte[] data) {
- return getShaDigest().digest(data);
- }
- /**
- * Calculates the SHA digest and returns the value as a
- * <code>byte[]</code>.
- *
- * @param data Data to digest
- * @return SHA digest
- */
- public staticbyte[] sha(String data){
- return sha(data.getBytes());
- }
- /**
- * Calculates the SHA digest and returns the value as a hex string.
- *
- * @param data Data to digest
- * @return SHA digest as a hex string
- */
- public staticString shaHex(byte[] data){
- return newString(Hex.encodeHex(sha(data)));
- }
- /**
- * Calculates the SHA digest and returns the value as a hex string.
- *
- * @param data Data to digest
- * @return SHA digest as a hex string
- */
- public staticString shaHex(String data){
- return newString(Hex.encodeHex(sha(data)));
- }
- }
0 0
- DigestUtils
- DigestUtils.md5Hex()加密
- DigestUtils工具类
- DigestUtils.md5Hex()加密
- md5加密(DigestUtils)
- 加密:DigestUtils与java MessageDigest
- apaceh commons-codec 加密工具类 DigestUtils
- Andoid DigestUtils.md5Hed("") Class Not Found Error
- 项目中的工具类StringUtils和DigestUtils
- DigestUtils加密工具类的使用
- java md5,sha编码工具类DigestUtils
- org.apache.commons.codec.digest.DigestUtils下载相关包
- Spring框架自带MD5 加密工具类 DigestUtils
- POI导出excel提示ClassNotFoundException: org.apache.commons.codec.digest.DigestUtils
- 解决resource directory '/xxx//res' does not exist的方法
- POJ Find them, Catch them
- 网络的可靠性
- C语言实现 球体下落路程及反弹高度求解
- [Leetcode 13, Easy] Roman To Integer
- DigestUtils
- HDU 1070 Milk
- c++远程下载
- ORACLE服务器进程处理用户进程请求的全过程
- 禁用Ajax使用浏览器缓存
- VMware串口
- 请找一个值得你爱的人去爱
- 音频播放协议AVAudioPlayerDelegate 函数简介
- android 蓝牙浅谈