public class SecretKeyFactory extends Object
 主要工厂用于将密钥 (类型为Key不透明加密密钥)转换为密钥规范 (基础密钥材料的透明表示),反之亦然。 秘密密钥工厂仅在秘密(对称)密钥上运行。 
关键工厂是双向的,即它们允许从给定的密钥规范(密钥材料)构建一个不透明的密钥对象,或以适当的格式检索密钥对象的基础密钥材料。
 应用程序开发人员应参考其提供商的文档,以了解generateSecret和getKeySpec方法支持哪些关键规范。 例如,“SunJCE”提供商提供的DES秘密密钥工厂支持DESKeySpec作为DES密钥的透明表示,该提供商的三重DES密钥密钥工厂支持DESedeKeySpec作为三重DES密钥的透明表示。 
 Java平台的每个实现都需要支持以下标准的SecretKeyFactory算法: 
SecretKey , DESKeySpec , DESedeKeySpec , PBEKeySpec 
       | Modifier | Constructor and Description | 
|---|---|
| protected  | SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)
              创建一个SecretKeyFactory对象。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| SecretKey | generateSecret(KeySpec keySpec)
              根据提供的密钥规范(密钥材料)生成一个 
              SecretKey对象。 | 
| String | getAlgorithm()
              返回此 
              SecretKeyFactory对象的算法名称。 | 
| static SecretKeyFactory | getInstance(String algorithm)
              返回 
              SecretKeyFactory对象转换指定算法的密钥。 | 
| static SecretKeyFactory | getInstance(String algorithm, Provider provider)
              返回 
              SecretKeyFactory对象转换指定算法的密钥。 | 
| static SecretKeyFactory | getInstance(String algorithm, String provider)
              返回 
              SecretKeyFactory对象转换指定算法的密钥。 | 
| KeySpec | getKeySpec(SecretKey key, 类<?> keySpec)
              以请求的格式返回给定键对象的规范(关键材料)。 
             | 
| Provider | getProvider()
              返回此 
              SecretKeyFactory对象的提供者。 | 
| SecretKey | translateKey(SecretKey key)
              将其提供者可能未知或可能不受信任的关键对象转换为该秘密密钥工厂的相应密钥对象。 
             | 
protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)
keyFacSpi - 代表 
           provider - 提供商 
           algorithm - 秘密密钥算法 
           public static final SecretKeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException
SecretKeyFactory对象转换指定算法的密钥。 
           此方法遍历已注册的安全提供程序列表,从最优选的提供程序开始。 返回从支持指定算法的第一个Provider中封装SecretKeyFactorySpi实现的新SecretKeyFactory对象。
 请注意,注册提供商的列表可以通过Security.getProviders()方法检索 。 
algorithm - 所请求密钥算法的标准名称。 
            看到的SecretKeyFactory部分Java Cryptography Architecture Standard Algorithm Name Documentation有关标准算法名称的信息。 
           SecretKeyFactory对象。 
           NullPointerException - 如果指定的算法为空。 
           NoSuchAlgorithmException - 如果没有提供者支持指定算法的SecretKeyFactorySpi实现。 
           Provider 
           public static final SecretKeyFactory getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
SecretKeyFactory对象转换指定算法的密钥。 
           返回从指定提供程序封装SecretKeyFactorySpi实现的新SecretKeyFactory对象。 指定的提供者必须在安全提供程序列表中注册。
 注意,可以通过Security.getProviders()方法检索已注册提供商的列表。 
algorithm - 所请求密钥算法的标准名称。 
            看到的SecretKeyFactory部分Java Cryptography Architecture Standard Algorithm Name Documentation有关标准算法名称的信息。 
           provider - 提供者的名称。 
           SecretKeyFactory对象。 
           NoSuchAlgorithmException - 如果指定算法的SecretKeyFactorySpi实现不能从指定的提供者获得。 
           NullPointerException - 如果指定的算法为空。 
           NoSuchProviderException - 如果指定的提供程序未在安全提供程序列表中注册。 
           IllegalArgumentException - 如果 
            provider为空或为空。 
           Provider 
           public static final SecretKeyFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
SecretKeyFactory对象转换指定算法的密钥。 
           返回从指定的Provider对象封装SecretKeyFactorySpi实现的新SecretKeyFactory对象。 请注意,指定的Provider对象不必在提供者列表中注册。
algorithm - 所请求密钥算法的标准名称。 
            看到的SecretKeyFactory部分Java Cryptography Architecture Standard Algorithm Name Documentation有关标准算法名称的信息。 
           provider - 提供商。 
           SecretKeyFactory对象。 
           NullPointerException - 如果指定的算法为空。 
           NoSuchAlgorithmException - 如果指定的算法的SecretKeyFactorySpi实现从指定的Provider对象不可用。 
           IllegalArgumentException - 如果 
            provider为空。 
           Provider 
           public final Provider getProvider()
SecretKeyFactory对象的提供者。 
          SecretKeyFactory对象的提供者 
           public final String getAlgorithm()
SecretKeyFactory对象的算法名称。 
            这是在创建此SecretKeyFactory对象的getInstance调用之一中指定的getInstance 。 
SecretKeyFactory对象的算法名称。 
           public final SecretKey generateSecret(KeySpec keySpec) throws InvalidKeySpecException
SecretKey对象。 
          keySpec - 秘密密钥的规范(密钥材料) 
           InvalidKeySpecException - 如果给定的密钥规范不适合该秘密密钥工厂生成密钥。 
           public final KeySpec getKeySpec(SecretKey key, 类<?> keySpec) throws InvalidKeySpecException
key - 关键 
           keySpec - 要求退还关键材料的要求格式 
           InvalidKeySpecException - 如果所请求的密钥规范对于给定的密钥是不合适的(例如,与 
            key和 
            keySpec不匹配,或 
            key引用加密硬件设备上的密钥,而 
            keySpec是基于软件的密钥的规范)或者给定的密钥不能被处理(例如,给定的密钥具有该秘密密钥工厂不支持的算法或格式)。 
           public final SecretKey translateKey(SecretKey key) throws InvalidKeyException
key - 提供者未知或不信任的关键 
           InvalidKeyException - 如果该密钥工厂无法处理给定的密钥。 
            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.