public class SecretKeyFactory extends Object
关键的工厂是用来将钥匙(不透明的密钥类型Key
)为主要规格(基础关键材料的透明表示),反之亦然。秘密密钥工厂只操作秘密(对称)密钥。
关键工厂是双向的,也就是说,他们允许建立一个不透明的关键对象从一个给定的关键规范(关键材料),或检索的基本关键材料的一个合适的格式的一个关键对象。
应用程序开发者应该参考他们的供应商的文档,找出其中的关键指标是由generateSecret
和getKeySpec
方法支持。例如,DES密钥厂以“sunjce提供者”支持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
转换指定的算法密钥。
该方法通过注册安全提供商列表,从最开始的首选供应商。一个新的secretkeyfactory对象封装secretkeyfactoryspi实施支持指定算法的第一供应商返回。
注意,注册商的列表可以通过Security.getProviders()
检索方法。
algorithm
-请求的密钥算法的标准名称。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation的secretkeyfactory节。
SecretKeyFactory
对象。
NullPointerException
-如果指定的算法是无效的。
NoSuchAlgorithmException
-如果没有提供程序支持一个指定的算法secretkeyfactoryspi实施。
Provider
public static final SecretKeyFactory getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
SecretKeyFactory
转换指定的算法密钥。
一个新的secretkeyfactory对象封装secretkeyfactoryspi实现从指定的提供程序返回。指定的提供程序必须在安全提供程序列表中注册。
注意,注册商的列表可以通过Security.getProviders()
检索方法。
algorithm
-请求的密钥算法的标准名称。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation的secretkeyfactory节。
provider
-提供者的名称。
SecretKeyFactory
对象。
NoSuchAlgorithmException
-如果一个指定的算法secretkeyfactoryspi执行不可从指定的供应商。
NullPointerException
-如果指定的算法是无效的。
NoSuchProviderException
-如果指定的供应商不在安全提供商注册名单。
IllegalArgumentException
-如果
provider
是null或空。
Provider
public static final SecretKeyFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
SecretKeyFactory
转换指定的算法密钥。
一个新的secretkeyfactory对象封装secretkeyfactoryspi实现从指定的提供程序对象返回。请注意,指定的提供程序对象不必在提供者列表中注册。
algorithm
-请求的密钥算法的标准名称。看到有关标准算法名称信息在
Java Cryptography Architecture Standard Algorithm Name Documentation的secretkeyfactory节。
provider
-供应商。
SecretKeyFactory
对象。
NullPointerException
-如果指定的算法是无效的。
NoSuchAlgorithmException
-如果一个指定的算法secretkeyfactoryspi执行不可从指定的提供程序对象。
IllegalArgumentException
-如果
provider
是空的。
Provider
public final Provider getProvider()
SecretKeyFactory
提供者。
SecretKeyFactory
对象的提供者
public final String getAlgorithm()
SecretKeyFactory
。
这是相同的名字,是在一个SecretKeyFactory
创建这个对象调用指定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.