|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjavax.crypto.Mac
public class Mac
此类提供“消息验证代码”(MAC) 算法的功能。
MAC 基于秘密密钥提供一种检查信息完整性的方法,该信息在不可靠的介质上传输或者存储在这种介质上。通常,消息验证代码在共享秘密密钥的两个参与者之间使用,以验证这两方之间传输的信息。
基于 cryptographic(加密)哈希函数的 MAC 机制也叫作 HMAC。HMAC 结合秘密共享密钥可以与任何 cryptographic 哈希函数(如 MD5 或 SHA-1)一起使用。HMAC 在 RFC 2104 中指定。
| 构造方法摘要 | |
|---|---|
protected |
Mac(MacSpi macSpi,
Provider provider,
String algorithm)
创建一个 MAC 对象。 |
| 方法摘要 | |
|---|---|
Object |
clone()
如果此提供程序实现可以复制,则返回一个副本。 |
byte[] |
doFinal()
完成 MAC 操作。 |
byte[] |
doFinal(byte[] input)
处理给定的字节数组并完成 MAC 操作。 |
void |
doFinal(byte[] output,
int outOffset)
完成 MAC 操作。 |
String |
getAlgorithm()
返回此 Mac 对象的算法名称。 |
static Mac |
getInstance(String algorithm)
生成实现指定 MAC 算法的 Mac 对象。 |
static Mac |
getInstance(String algorithm,
Provider provider)
根据指定的提供程序生成指定 MAC 算法的 Mac 对象。 |
static Mac |
getInstance(String algorithm,
String provider)
根据指定的提供程序生成指定 MAC 算法的 Mac 对象。 |
int |
getMacLength()
返回以字节为单位的 MAC 的长度。 |
Provider |
getProvider()
返回此 Mac 对象的提供程序。 |
void |
init(Key key)
用给定的密钥初始化此 Mac 对象。 |
void |
init(Key key,
AlgorithmParameterSpec params)
用给定的密钥和算法参数初始化此 Mac 对象。 |
void |
reset()
重新设置此 Mac 对象。 |
void |
update(byte input)
处理给定的字节。 |
void |
update(byte[] input)
处理给定的字节数组。 |
void |
update(byte[] input,
int offset,
int len)
从 offset 开始处(包含),处理 input 中的第一个 len 字节。 |
void |
update(ByteBuffer input)
从 input.position() 开始处,处理 ByteBuffer input 中的 input.remaining() 字节。 |
| 从类 java.lang.Object 继承的方法 |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
protected Mac(MacSpi macSpi,
Provider provider,
String algorithm)
macSpi - 代理provider - 提供程序algorithm - 算法| 方法详细信息 |
|---|
public final String getAlgorithm()
Mac 对象的算法名称。
此名称与在某个创建此 Mac 对象的 getInstance 调用中指定的名称相同。
Mac 对象的算法名称。
public static final Mac getInstance(String algorithm)
throws NoSuchAlgorithmException
Mac 对象。如果默认提供程序包提供请求的 MAC 算法的实现,则返回包含该实现的一个 Mac 实例。如果默认的提供程序包中没有可用的算法,则将搜索其他的提供程序包。
algorithm - 请求的 MAC 算法的标准名称。有关标准算法名称的信息,请参阅《Java Cryptography Extension Reference Guide》中的附录 A。
Mac 对象
NoSuchAlgorithmException - 如果默认的提供程序包中指定的算法不可用,或者搜索到的其他提供程序包都不可用。
public static final Mac getInstance(String algorithm,
String provider)
throws NoSuchAlgorithmException,
NoSuchProviderException
Mac 对象。
algorithm - 请求的 MAC 算法的标准名称。有关标准算法名称的信息,请参阅《Java Cryptography Extension Reference Guide》中的附录 A。provider - 提供程序的名称。
Mac 对象。
NoSuchAlgorithmException - 如果指定的提供程序中未提供指定的算法。
NoSuchProviderException - 如果指定的提供程序未配置。
IllegalArgumentException - 如果 provider 为 null。
public static final Mac getInstance(String algorithm,
Provider provider)
throws NoSuchAlgorithmException
Mac 对象。注:provider 不一定都需要注册。
algorithm - 请求的 MAC 算法的标准名称。有关标准算法名称的信息,请参阅《Java Cryptography Extension Reference Guide》中的附录 A。provider - 提供程序的名称。
Mac 对象。
NoSuchAlgorithmException - 如果指定的提供程序中未提供指定的算法。
IllegalArgumentException - 如果 provider 为 null。public final Provider getProvider()
Mac 对象的提供程序。
Mac 对象的提供程序。public final int getMacLength()
public final void init(Key key)
throws InvalidKeyException
Mac 对象。
key - 密钥。
InvalidKeyException - 如果给定密钥不适合初始化此 MAC。
public final void init(Key key,
AlgorithmParameterSpec params)
throws InvalidKeyException,
InvalidAlgorithmParameterException
Mac 对象。
key - 密钥。params - 算法参数。
InvalidKeyException - 如果给定密钥不适合初始化此 MAC。
InvalidAlgorithmParameterException - 如果给定算法参数不适合此 MAC。
public final void update(byte input)
throws IllegalStateException
input - 要处理的输入字节。
IllegalStateException - 如果尚未初始化此 Mac。
public final void update(byte[] input)
throws IllegalStateException
input - 要处理的字节数组。
IllegalStateException - 如果尚未初始化此 Mac。
public final void update(byte[] input,
int offset,
int len)
throws IllegalStateException
offset 开始处(包含),处理 input 中的第一个 len 字节。
input - 输入缓冲区。offset - input 中输入开始处的偏移量。len - 要处理的字节数。
IllegalStateException - 如果尚未初始化此 Mac。public final void update(ByteBuffer input)
input.position() 开始处,处理 ByteBuffer input 中的 input.remaining() 字节。返回时,缓冲区的位置将等于其限制;其限制并未改变。
input - ByteBuffer
IllegalStateException - 如果尚未初始化此 Mac。
public final byte[] doFinal()
throws IllegalStateException
对此方法的调用将把此 Mac 对象重新设置为以前通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其初始化时的状态。也就是说,如果需要,通过重新调用 update 和 doFinal,可重新设置对象,并通过它可用同一个密钥生成其他人的 MAC。(为了用不同的密钥重新使用此 Mac 对象,必须通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其重新初始化)。
IllegalStateException - 如果尚未初始化此 Mac。
public final void doFinal(byte[] output,
int outOffset)
throws ShortBufferException,
IllegalStateException
对此方法的调用将把此 Mac 对象重新设置为以前通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其初始化时的状态。也就是说,如果需要,通过重新调用 update 和 doFinal,可重新设置对象,并通过它可用同一个密钥生成其他人的 MAC。(为了用不同的密钥重新使用此 Mac 对象,必须通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其重新初始化)。
MAC 结果存储在 output 中从 outputOffset 开始的位置(包含)。
output - 存储 MAC 结果的缓冲区outOffset - output 中存储 MAC 处的偏移量
ShortBufferException - 如果给定输出缓冲区太小不能存储该结果
IllegalStateException - 如果尚未初始化此 Mac。
public final byte[] doFinal(byte[] input)
throws IllegalStateException
对此方法的调用将把此 Mac 对象重新设置为以前通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其初始化时的状态。也就是说,如果需要,通过重新调用 update 和 doFinal,可重新设置对象,并通过它可用同一个密钥生成其他人的 MAC。(为了用不同的密钥重新使用此 Mac 对象,必须通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其重新初始化)。
input - 字节中的数据
IllegalStateException - 如果尚未初始化此 Mac。public final void reset()
Mac 对象。
对此方法的调用将把此 Mac 对象重新设置为以前通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其初始化时的状态。也就是说,如果需要,通过重新调用 update 和 doFinal,可重新设置对象,并通过它可用同一个密钥生成其他人的 MAC。(为了用不同的密钥重新使用此 Mac 对象,必须通过调用 init(Key) 或 init(Key, AlgorithmParameterSpec) 对其重新初始化。
public final Object clone()
throws CloneNotSupportedException
Object 中的 cloneCloneNotSupportedException - 如果这是对不支持 Cloneable 的代理调用。Cloneable
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。