public abstract class Signature extends SignatureSpi
签名算法即可,其中,NIST标准DSA,DSA和SHA-1。采用SHA-1信息摘要算法DSA算法可以被指定为SHA1withDSA
。在RSA的情况下,有多种选择的消息摘要算法,所以签名算法可以被指定为,例如,MD2withRSA
,MD5withRSA
,或SHA1withRSA
。必须指定该算法名称,因为没有默认值。
签名的对象可以用来生成和验证数字签名。
有三个阶段使用的签名对象的签名数据或验证签名:
initVerify
),或initSign(PrivateKey)
和initSign(PrivateKey, SecureRandom)
)。根据初始化的类型,这将更新要签名或验证的字节数。看到update
方法。
sign
方法和verify
方法。请注意,这个类是抽象的,从历史原因SignatureSpi
延伸。应用程序开发人员只需要在这Signature
类中定义的方法的通知;在父类的所有方法都用于加密服务供应商希望提供自己的数字签名算法的实现。
java平台的每种实现都要求支持以下标准Signature
算法:
SHA1withDSA
SHA1withRSA
SHA256withRSA
Modifier and Type | Field and Description |
---|---|
protected static int |
SIGN
可能
state 值,表示这个签名对象被初始化为签约。
|
protected int |
state
这个签名对象的当前状态。
|
protected static int |
UNINITIALIZED
可能
state 值,表示这个签名对象尚未初始化。
|
protected static int |
VERIFY
可能
state 值,表示该对象已被初始化为验证签名。
|
appRandom
Modifier | Constructor and Description |
---|---|
protected |
Signature(String algorithm)
为指定的算法创建一个签名对象。
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
返回一个克隆如果实现Cloneable。
|
String |
getAlgorithm()
返回此签名对象的算法的名称。
|
static Signature |
getInstance(String algorithm)
返回一个实现指定签名算法的签名对象。
|
static Signature |
getInstance(String algorithm, Provider provider)
返回一个实现指定签名算法的签名对象。
|
static Signature |
getInstance(String algorithm, String provider)
返回一个实现指定签名算法的签名对象。
|
Object |
getParameter(String param)
过时的。
|
AlgorithmParameters |
getParameters()
返回与此签名对象使用的参数。
|
Provider |
getProvider()
返回此签名对象的提供程序。
|
void |
initSign(PrivateKey privateKey)
初始化此对象的签名。
|
void |
initSign(PrivateKey privateKey, SecureRandom random)
初始化此对象的签名。
|
void |
initVerify(Certificate certificate)
初始化这个对象的验证,使用给定的证书的公钥。
|
void |
initVerify(PublicKey publicKey)
初始化这个对象的验证。
|
void |
setParameter(AlgorithmParameterSpec params)
用指定的参数初始化这个签名引擎。
|
void |
setParameter(String param, Object value)
过时的。
使用
setParameter 。
|
byte[] |
sign()
返回更新的所有数据的签名字节。
|
int |
sign(byte[] outbuf, int offset, int len)
完成签名操作和存储造成签名字节缓冲区的设置
outbuf ,开始在
offset 。
|
String |
toString()
返回此签名对象的字符串表示形式,提供包含该对象的状态和所使用的算法的名称的信息。
|
void |
update(byte b)
更新要由字节签名或验证的数据。
|
void |
update(byte[] data)
更新要签名或验证的数据,使用指定的字节数组。
|
void |
update(byte[] data, int off, int len)
更新要签名或验证的数据,使用指定的字节数组,从指定的偏移量开始。
|
void |
update(ByteBuffer data)
要签名的数据或使用指定验证更新ByteBuffer。
|
boolean |
verify(byte[] signature)
验证签名中的通过。
|
boolean |
verify(byte[] signature, int offset, int length)
将在指定的字节数中指定的字节数组中的签名进行验证,从指定的偏移量开始。
|
engineGetParameter, engineGetParameters, engineInitSign, engineInitSign, engineInitVerify, engineSetParameter, engineSetParameter, engineSign, engineSign, engineUpdate, engineUpdate, engineUpdate, engineVerify, engineVerify
protected static final int UNINITIALIZED
state
值,表示这个签名对象尚未初始化。
protected static final int SIGN
state
值,表示这个签名对象被初始化为签约。
protected static final int VERIFY
state
值,表示该对象已被初始化为验证签名。
protected int state
protected Signature(String algorithm)
algorithm
-算法的标准字符串名称。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation签名部分。
public static Signature getInstance(String algorithm) throws NoSuchAlgorithmException
该方法通过注册安全提供商列表,从最开始的首选供应商。一个新的签名对象封装signaturespi实施支持指定算法的第一供应商返回。
注意,注册商的列表可以通过Security.getProviders()
检索方法。
algorithm
-算法的标准名称要求。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation签名部分。
NoSuchAlgorithmException
-如果没有提供程序支持一个指定的算法签名的实现。
Provider
public static Signature getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
一个新的签名对象封装signaturespi实现从指定的提供程序返回。指定的提供程序必须在安全提供程序列表中注册。
注意,注册商的列表可以通过Security.getProviders()
检索方法。
algorithm
-算法的名字要求。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation签名部分。
provider
-提供者的名称。
NoSuchAlgorithmException
-如果一个指定的算法signaturespi执行不可从指定的供应商。
NoSuchProviderException
-如果指定的供应商不在安全提供商注册名单。
IllegalArgumentException
如果提供者名称为空或空。
Provider
public static Signature getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
一个新的签名对象封装signaturespi实现从指定的提供程序对象返回。请注意,指定的提供程序对象不必在提供者列表中注册。
algorithm
-算法的名字要求。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation签名部分。
provider
-供应商。
NoSuchAlgorithmException
-如果一个指定的算法signaturespi执行不可从指定的提供程序对象。
IllegalArgumentException
如果供应商是空的。
Provider
public final Provider getProvider()
public final void initVerify(PublicKey publicKey) throws InvalidKeyException
publicKey
-身份的签名来验证公钥。
InvalidKeyException
如果密钥无效。
public final void initVerify(Certificate certificate) throws InvalidKeyException
如果证书的类型是X.509和有密钥用法扩展字段标记为关键,对密钥用法扩展字段的值意味着在证书和对应的私钥公钥不应该用于数字签名的一个InvalidKeyException
抛出。
certificate
的身份的签名将被验证证书。
InvalidKeyException
如果证书中的公钥不适当地编码或不包括所需的参数信息或不能用于数字签名的目的。
public final void initSign(PrivateKey privateKey) throws InvalidKeyException
privateKey
-身份的签名将要生成的私钥。
InvalidKeyException
如果密钥无效。
public final void initSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException
privateKey
-身份的签名将要生成的私钥。
random
-此签名的随机源。
InvalidKeyException
如果密钥无效。
public final byte[] sign() throws SignatureException
调用此方法将这个签名对象时的状态之前初始化签署通过调用initSign(PrivateKey)
。那就是,对象是复位可从相同的签名,生成另一个签名,如果需要的话,通过新的电话update
和sign
。
SignatureException
-如果这签名对象初始化不正确或如果这签名算法无法处理输入数据的提供。
public final int sign(byte[] outbuf, int offset, int len) throws SignatureException
outbuf
,开始在
offset
。签名的格式取决于基础的签名方案。
这个签名对象重置为其初始状态(的状态是在打电话的一个initSign
方法后)和可重复产生相同的签名私钥进一步。
outbuf
-签名结果缓冲区。
offset
偏移到
outbuf
哪里签名存储。
outbuf
len
。
outbuf
字节数。
SignatureException
-如果这签名对象初始化不正确,如果这个签名算法无法处理提供输入数据,或者如果
len
小于实际签名长度。
public final boolean verify(byte[] signature) throws SignatureException
调用此方法将这个签名对象时的状态之前初始化验证通过电话initVerify(PublicKey)
。那就是,对象是复位和可验证身份的公钥被指定在调用initVerify
另一个签名。
signature
-签名字节进行验证。
SignatureException
-如果这签名对象初始化不正确,通过签名编码不正确或错误的类型,如果这个签名算法无法处理提供输入数据,等等。
public final boolean verify(byte[] signature, int offset, int length) throws SignatureException
调用此方法将这个签名对象时的状态之前初始化验证通过电话initVerify(PublicKey)
。那就是,对象是复位和可验证身份的公钥被指定在调用initVerify
另一个签名。
signature
-签名字节进行验证。
offset
-偏移量开始从字节数组。
length
-使用的字节数,起始偏移。
SignatureException
-如果这签名对象初始化不正确,通过签名编码不正确或错误的类型,如果这个签名算法无法处理提供输入数据,等等。
IllegalArgumentException
-如果
signature
字节数组为空,或
offset
或
length
小于0,或对
offset
和
length
总和大于的
signature
字节数组的长度。
public final void update(byte b) throws SignatureException
b
-字节用于更新。
SignatureException
-如果这签名对象初始化不正确。
public final void update(byte[] data) throws SignatureException
data
-使用更新的字节数组。
SignatureException
-如果这签名对象初始化不正确。
public final void update(byte[] data, int off, int len) throws SignatureException
data
-字节数组。
off
-偏移量开始从字节数组。
len
-使用的字节数,起始偏移。
SignatureException
-如果这签名对象初始化不正确。
public final void update(ByteBuffer data) throws SignatureException
data.remaining()
字节开始在
data.position()
。当返回时,缓冲区的位置将等于它的极限,它的限制不会改变。
data
- ByteBuffer
SignatureException
-如果这签名对象初始化不正确。
public final String getAlgorithm()
public String toString()
@Deprecated public final void setParameter(String param, Object value) throws InvalidParameterException
setParameter
。
param
-参数标识符字符串。
value
-参数值。
InvalidParameterException
-如果
param
是这个签名算法引擎无效的参数,参数已经确定,不能再设置,发生安全异常,等等。
getParameter(java.lang.String)
public final void setParameter(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException
params
-参数
InvalidAlgorithmParameterException
-如果给定的参数不合适这个签名引擎
getParameters()
public final AlgorithmParameters getParameters()
返回的参数可能是相同的,用于初始化这个签名,或可能包含默认值和随机生成的参数值的组合使用的基础签名的实现,如果这个签名需要算法参数,但没有初始化。
setParameter(AlgorithmParameterSpec)
@Deprecated public final Object getParameter(String param) throws InvalidParameterException
param
-参数的字符串名称。
InvalidParameterException
-如果
param
是这个发动机的参数无效,或另一个例外发生在试图让这个参数。
setParameter(String, Object)
public Object clone() throws CloneNotSupportedException
clone
方法重写,继承类
SignatureSpi
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.