public class SecretKeySpec
extends Object implements KeySpec, SecretKey
| java.lang.Object | |
| javax.crypto.spec.SecretKeySpec | |
该类以独立于提供者的方式指定密钥。
它可用于从字节数组构建 SecretKey ,而无需通过(基于提供者) SecretKeyFactory 。
该类仅对可以表示为字节数组且没有与它们相关联的关键参数(例如,DES或三重DES密钥)的原始密钥有用。
也可以看看:
Inherited constants |
|---|
javax.crypto.SecretKey
|
java.security.Key
|
Public constructors |
|
|---|---|
SecretKeySpec(byte[] key, String algorithm) 从给定的字节数组构造一个密钥。 |
|
SecretKeySpec(byte[] key, int offset, int len, String algorithm) 使用 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
equals(Object obj) 测试指定对象和此对象之间的相等性。 |
String |
getAlgorithm() 返回与此密钥相关的算法的名称。 |
byte[] |
getEncoded() 返回此密钥的密钥材料。 |
String |
getFormat() 返回此密钥的编码格式的名称。 |
int |
hashCode() 计算该对象的哈希码值。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
java.security.Key
|
|
SecretKeySpec (byte[] key,
String algorithm)
从给定的字节数组构造一个密钥。
此构造函数不检查给定的字节是否确实指定了指定算法的密钥。 例如,如果算法是DES,则此构造函数不会检查key是否为8个字节长,也不检查弱密钥或半弱密钥。 为了执行这些检查,应该使用特定于算法的密钥规范类(在此例中为DESKeySpec )。
| 参数(Parameters) | |
|---|---|
key |
byte: the key material of the secret key. The contents of the array are copied to protect against subsequent modification. |
algorithm |
String: the name of the secret-key algorithm to be associated with the given key material. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard algorithm names. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if algorithm is null or key is null or empty. |
SecretKeySpec (byte[] key,
int offset,
int len,
String algorithm)
根据给定的字节数组的秘密密钥,使用所述第一 len的字节 key ,起始于 offset以下。
构成密钥的字节是 key[offset]和 key[offset+len-1]之间的那些字节。
此构造函数不检查给定的字节是否确实指定了指定算法的密钥。 例如,如果算法是DES,则此构造函数不检查key是否是8个字节长,也不检查弱密钥或半弱密钥。 为了执行这些检查,必须使用特定于算法的密钥规范类(在此例中为DESKeySpec )。
| 参数(Parameters) | |
|---|---|
key |
byte: the key material of the secret key. The first len bytes of the array beginning at offset inclusive are copied to protect against subsequent modification. |
offset |
int: the offset in key where the key material starts. |
len |
int: the length of the key material. |
algorithm |
String: the name of the secret-key algorithm to be associated with the given key material. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard algorithm names. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if algorithm is null or key is null, empty, or too short, i.e. key.length-offset
|
ArrayIndexOutOfBoundsException |
is thrown if offset or len index bytes outside the key. |
boolean equals (Object obj)
测试指定对象和此对象之间的相等性。 如果两个SecretKeySpec对象都是具有相同的不区分大小写算法名称和密钥编码的SecretKey实例,则认为它们是相等的。
| 参数(Parameters) | |
|---|---|
obj |
Object: the object to test for equality with this object. |
| 返回(Returns) | |
|---|---|
boolean |
true if the objects are considered equal, false if obj is null or otherwise. |
String getAlgorithm ()
返回与此密钥相关的算法的名称。
| 返回(Returns) | |
|---|---|
String |
the secret key algorithm. |
byte[] getEncoded ()
返回此密钥的密钥材料。
| 返回(Returns) | |
|---|---|
byte[] |
the key material. Returns a new array each time this method is called. |
String getFormat ()
返回此密钥的编码格式的名称。
| 返回(Returns) | |
|---|---|
String |
the string "RAW". |
int hashCode ()
计算该对象的哈希码值。 相等的对象也将具有相同的哈希码。
| 返回(Returns) | |
|---|---|
int |
a hash code value for this object. |