public class HMac extends Object implements Serializable
| Constructor and Description |
|---|
HMac(org.aoju.bus.core.lang.Algorithm algorithm)
构造,自动生成密钥
|
HMac(org.aoju.bus.core.lang.Algorithm algorithm,
byte[] key)
构造
|
HMac(org.aoju.bus.core.lang.Algorithm algorithm,
Key key)
构造
|
HMac(MacEngine engine)
构造
|
HMac(String algorithm,
byte[] key)
构造
|
HMac(String algorithm,
Key key)
构造
|
HMac(String algorithm,
Key key,
AlgorithmParameterSpec spec)
构造
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
digest(byte[] data)
生成摘要
|
byte[] |
digest(File file)
生成文件摘要
使用默认缓存大小,见
IoKit.DEFAULT_BUFFER_SIZE |
byte[] |
digest(InputStream data)
生成摘要,使用默认缓存大小,见
IoKit.DEFAULT_BUFFER_SIZE |
byte[] |
digest(InputStream data,
int bufferLength)
生成摘要
|
byte[] |
digest(String data)
生成文件摘要
|
byte[] |
digest(String data,
Charset charset)
生成文件摘要
|
String |
digestBase64(String data,
boolean isUrlSafe)
生成文件摘要,并转为Base64
|
String |
digestBase64(String data,
Charset charset,
boolean isUrlSafe)
生成文件摘要,并转为Base64
|
String |
digestHex(byte[] data)
生成摘要,并转为16进制字符串
|
String |
digestHex(File file)
生成文件摘要,并转为16进制字符串
使用默认缓存大小,见
IoKit.DEFAULT_BUFFER_SIZE |
String |
digestHex(InputStream data)
生成摘要,并转为16进制字符串
使用默认缓存大小,见
IoKit.DEFAULT_BUFFER_SIZE |
String |
digestHex(InputStream data,
int bufferLength)
生成摘要,并转为16进制字符串
使用默认缓存大小,见
IoKit.DEFAULT_BUFFER_SIZE |
String |
digestHex(String data)
生成文件摘要
|
String |
digestHex(String data,
Charset charset)
生成文件摘要,并转为16进制字符串
|
String |
getAlgorithm()
获取算法
|
MacEngine |
getEngine()
获得MAC算法引擎
|
int |
getMacLength()
获取MAC算法块长度
|
boolean |
verify(byte[] digest,
byte[] digestToCompare)
验证生成的摘要与给定的摘要比较是否一致
简单比较每个byte位是否相同
|
public HMac(org.aoju.bus.core.lang.Algorithm algorithm)
algorithm - 算法 Algorithmpublic HMac(org.aoju.bus.core.lang.Algorithm algorithm,
byte[] key)
algorithm - 算法 Algorithmkey - 密钥public HMac(org.aoju.bus.core.lang.Algorithm algorithm,
Key key)
algorithm - 算法 Algorithmkey - 密钥public HMac(String algorithm, byte[] key)
algorithm - 算法key - 密钥public HMac(String algorithm, Key key, AlgorithmParameterSpec spec)
algorithm - 算法key - 密钥spec - AlgorithmParameterSpecpublic HMac(MacEngine engine)
engine - MAC算法实现引擎public MacEngine getEngine()
public byte[] digest(String data, Charset charset)
data - 被摘要数据charset - 编码public byte[] digest(String data)
data - 被摘要数据public String digestBase64(String data, boolean isUrlSafe)
data - 被摘要数据isUrlSafe - 是否使用URL安全字符public String digestBase64(String data, Charset charset, boolean isUrlSafe)
data - 被摘要数据charset - 编码isUrlSafe - 是否使用URL安全字符public String digestHex(String data, Charset charset)
data - 被摘要数据charset - 编码public byte[] digest(File file) throws org.aoju.bus.core.lang.exception.CryptoException
IoKit.DEFAULT_BUFFER_SIZEfile - 被摘要文件org.aoju.bus.core.lang.exception.CryptoException - Cause by IOExceptionpublic String digestHex(File file)
IoKit.DEFAULT_BUFFER_SIZEfile - 被摘要文件public byte[] digest(byte[] data)
data - 数据bytespublic String digestHex(byte[] data)
data - 被摘要数据public byte[] digest(InputStream data)
IoKit.DEFAULT_BUFFER_SIZEdata - InputStream 数据流public String digestHex(InputStream data)
IoKit.DEFAULT_BUFFER_SIZEdata - 被摘要数据public byte[] digest(InputStream data, int bufferLength)
data - InputStream 数据流bufferLength - 缓存长度,不足1使用 IoKit.DEFAULT_BUFFER_SIZE 做为默认值public String digestHex(InputStream data, int bufferLength)
IoKit.DEFAULT_BUFFER_SIZEdata - 被摘要数据bufferLength - 缓存长度,不足1使用 IoKit.DEFAULT_BUFFER_SIZE 做为默认值public boolean verify(byte[] digest,
byte[] digestToCompare)
digest - 生成的摘要digestToCompare - 需要比较的摘要MessageDigest.isEqual(byte[], byte[])public int getMacLength()
public String getAlgorithm()
Copyright © 2021. All rights reserved.