public abstract class MessageDigest extends MessageDigestSpi
一个消息摘要开始初始化对象。数据处理通过使用update方法。在任何时候reset可以称为重置消化。一旦所有的数据被更新已更新,其中的一个digest方法应该叫完成哈希计算。
的digest方法可以称为一次给定数量的更新。在digest被称为消息摘要对象重置为其初始状态。
实现自由实现Cloneable接口。客户端应用程序可以通过尝试和捕捉clonenotsupportedexception克隆试验cloneability:
MessageDigest md = MessageDigest.getInstance("SHA");
try {
md.update(toChapter1);
MessageDigest tc1 = md.clone();
byte[] toChapter1Digest = tc1.digest();
md.update(toChapter2);
...etc.
} catch (CloneNotSupportedException cnse) {
throw new DigestException("couldn't make digest of partial content");
}
注意,如果一个给定的实现是不可复制的,它仍然是可以通过实例化的实例计算中间消化,如果消化的数量是已知的。
请注意,这个类是抽象的,从历史原因MessageDigestSpi延伸。应用程序开发人员只需要在这MessageDigest类中定义的方法的通知;在父类的所有方法都用于加密服务供应商希望提供自己的消息摘要算法的实现。
java平台的每种实现都要求支持以下标准MessageDigest算法:
MD5SHA-1SHA-256| Modifier | Constructor and Description |
|---|---|
protected |
MessageDigest(String algorithm)
用指定的算法名称创建一个消息摘要。
|
| Modifier and Type | Method and Description |
|---|---|
Object |
clone()
返回一个克隆如果实现Cloneable。
|
byte[] |
digest()
通过执行诸如填充之类的最终操作来完成哈希计算。
|
byte[] |
digest(byte[] input)
使用指定的字节数组对摘要执行最后一个更新,然后完成摘要计算。
|
int |
digest(byte[] buf, int offset, int len)
通过执行诸如填充之类的最终操作来完成哈希计算。
|
String |
getAlgorithm()
返回一个确定该算法的字符串,独立于实现细节。
|
int |
getDigestLength()
返回的字节长度的消化,或0如果操作的提供程序不支持和执行不可复制。
|
static MessageDigest |
getInstance(String algorithm)
返回一个消息摘要对象实现指定的摘要算法。
|
static MessageDigest |
getInstance(String algorithm, Provider provider)
返回一个消息摘要对象实现指定的摘要算法。
|
static MessageDigest |
getInstance(String algorithm, String provider)
返回一个消息摘要对象实现指定的摘要算法。
|
Provider |
getProvider()
返回此邮件摘要对象的提供程序。
|
static boolean |
isEqual(byte[] digesta, byte[] digestb)
比较两个相等的消化。
|
void |
reset()
重置为进一步利用消化。
|
String |
toString()
返回此邮件摘要对象的字符串表示形式。
|
void |
update(byte input)
使用指定的字节来更新摘要。
|
void |
update(byte[] input)
使用指定的字节数组来更新摘要。
|
void |
update(byte[] input, int offset, int len)
使用指定的偏移量开始在指定的偏移量上更新使用指定的字节数组的摘要。
|
void |
update(ByteBuffer input)
使用指定的ByteBuffer更新摘要。
|
engineDigest, engineDigest, engineGetDigestLength, engineReset, engineUpdate, engineUpdate, engineUpdateprotected MessageDigest(String algorithm)
algorithm -摘要算法的标准名称。看在
Java Cryptography Architecture Standard Algorithm Name Documentation有关标准算法名称信息消息摘要部分。
public static MessageDigest getInstance(String algorithm) throws NoSuchAlgorithmException
该方法通过注册安全提供商列表,从最开始的首选供应商。一个新的消息摘要对象封装messagedigestspi实施支持指定算法的第一供应商返回。
注意,注册商的列表可以通过Security.getProviders()检索方法。
algorithm -算法的名字要求。看在
Java Cryptography Architecture Standard Algorithm Name Documentation有关标准算法名称信息消息摘要部分。
NoSuchAlgorithmException -如果没有提供程序支持一个指定的算法messagedigestspi实施。
Provider
public static MessageDigest getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
一个新的消息摘要对象封装messagedigestspi实现从指定的提供程序返回。指定的提供程序必须在安全提供程序列表中注册。
注意,注册商的列表可以通过Security.getProviders()检索方法。
algorithm -算法的名字要求。看在
Java Cryptography Architecture Standard Algorithm Name Documentation有关标准算法名称信息消息摘要部分。
provider -提供者的名称。
NoSuchAlgorithmException -如果一个指定的算法messagedigestspi执行不可从指定的供应商。
NoSuchProviderException -如果指定的供应商不在安全提供商注册名单。
IllegalArgumentException如果提供者名称为空或空。
Provider
public static MessageDigest getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
一个新的消息摘要对象封装messagedigestspi实现从指定的提供程序对象返回。请注意,指定的提供程序对象不必在提供者列表中注册。
algorithm -算法的名字要求。看在
Java Cryptography Architecture Standard Algorithm Name Documentation有关标准算法名称信息消息摘要部分。
provider -供应商。
NoSuchAlgorithmException -如果一个指定的算法messagedigestspi执行不可从指定的提供程序对象。
IllegalArgumentException -如果指定的提供程序是无效的。
Provider
public final Provider getProvider()
public void update(byte input)
input与字节更新摘要。
public void update(byte[] input,
int offset,
int len)
input -字节数组。
offset -偏移量开始从字节数组。
len -使用的字节数,从
offset。
public void update(byte[] input)
input -字节数组。
public final void update(ByteBuffer input)
input.remaining()字节开始
input.position()更新。当返回时,缓冲区的位置将等于它的极限,它的限制不会改变。
input - ByteBuffer
public byte[] digest()
public int digest(byte[] buf,
int offset,
int len)
throws DigestException
buf -计算摘要输出缓冲区
offset到输出缓冲区偏移开始储存消化
len消化
buf字节数
DigestException -如果出现错误。
public byte[] digest(byte[] input)
input -被更新之前消化完毕输入。
public static boolean isEqual(byte[] digesta,
byte[] digestb)
digesta -一个摘要比较。
digestb -其他消化比较。
public void reset()
public final String getAlgorithm()
public final int getDigestLength()
public Object clone() throws CloneNotSupportedException
clone 方法重写,继承类
MessageDigestSpi
CloneNotSupportedException -如果这是号召,不支持
Cloneable实施。
Cloneable
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.