public class SecretKeySpec extends Object implements KeySpec, SecretKey
 它可以用于从字节数组构造一个SecretKey ,而无需经过(基于提供者的) SecretKeyFactory 。 
此类仅对可以表示为字节数组并且没有与其相关联的关键参数的原始密钥(例如DES或三重DES密钥)有用。
SecretKey , SecretKeyFactory , Serialized Form 
       | Constructor and Description | 
|---|
| SecretKeySpec(byte[] key, int offset, int len, String algorithm)
              根据给定的字节数组的秘密密钥,使用所述第一 
              len的字节key,起始于offset以下。 | 
| SecretKeySpec(byte[] key, String algorithm)
              从给定的字节数组构造一个秘密密钥。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| boolean | equals(Object obj)
              测试指定对象和此对象之间的相等性。 
             | 
| String | getAlgorithm()
              返回与该密钥相关联的算法的名称。 
             | 
| byte[] | getEncoded()
              返回此密钥的密钥材料。 
             | 
| String | getFormat()
              返回此密钥的编码格式的名称。 
             | 
| int | hashCode()
              计算对象的哈希码值。 
             | 
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitdestroy, isDestroyedpublic SecretKeySpec(byte[] key,
                     String algorithm) 
           该构造函数不检查给定字节是否确实指定了指定算法的秘密密钥。 例如,如果算法是DES,那么这个构造函数不会检查key是否为8个字节长,也不会检查弱或半弱的密钥。 为了执行这些检查,应该使用特定于算法的密钥规范类(在这种情况下为DESKeySpec )。 
key - 密钥的关键材料。 
            复制数组的内容以防止后续修改。 
           algorithm - 与给定密钥材料相关联的秘密密钥算法的名称。 
            有关标准算法名称的信息,请参阅Java Cryptography Architecture Reference Guide中的附录A. 
           IllegalArgumentException - 如果 
            algorithm为空或 
            key为空或为空。 
           public SecretKeySpec(byte[] key,
                     int offset,
                     int len,
                     String algorithm) 
          len的字节key ,起始于offset以下。 
            构成密钥的字节在之间key[offset]和key[offset+len-1]包容性。 
 该构造函数不检查给定字节是否确实指定了指定算法的秘密密钥。 例如,如果算法是DES,那么这个构造函数不会检查key是否为8个字节长,也不会检查弱或半弱的密钥。 为了执行这些检查,必须使用特定于算法的密钥规范类(在这种情况下为DESKeySpec )。 
key - 密钥的关键材料。 
            第一len字节开始处所述阵列的offset包容被复制到防止后续修改。 
           offset - 关键材料启动时的偏移量 
            key 。 
           len - 关键材料的长度。 
           algorithm - 与给定密钥材料相关联的秘密密钥算法的名称。 
            有关标准算法名称的信息,请参阅Java Cryptography Architecture Reference Guide中的附录A. 
           IllegalArgumentException - 如果 
            algorithm为null或 
            key为空,空或太短,即 
            key.length-offset<len 。 
           ArrayIndexOutOfBoundsException - 如果 
            offset或 
            len索引字节在 
            key之外 
            key 。 
           public String getAlgorithm()
getAlgorithm在界面 
            Key 
           public byte[] getEncoded()
getEncoded在界面 
            Key 
           public int hashCode()
hashCode在 
            Object 
           Object.equals(java.lang.Object) , 
            System.identityHashCode(java.lang.Object) 
           public boolean equals(Object obj)
equals在类别 
            Object 
           obj - 测试与此对象相等的对象。 
           obj为 
            obj为false。 
           Object.hashCode() , HashMap 
            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.