Most visited

Recently visited

Added in API level 1

SecretKeyFactory

public class SecretKeyFactory
extends Object

java.lang.Object
   ↳ javax.crypto.SecretKeyFactory


这个类代表一个秘密密钥的工厂。

密钥工厂用于将密钥Key类型的不透明密码密钥)转换为密钥规范 (底层密钥资料的透明表示),反之亦然。 秘密密钥工厂仅在秘密(对称)密钥上运行。

主要工厂是双向的,即它们允许从给定的密钥规范(密钥材料)构建不透明的密钥对象,或以合适的格式检索密钥对象的基础密钥材料。

应用程序开发人员应参考其提供商的文档,了解generateSecretgetKeySpec方法支持哪些关键规范。 例如,由“SunJCE”供应商提供的DES密钥工厂支持DESKeySpec作为DES密钥的透明表示,该提供商的Triple DES密钥的密钥工厂支持DESedeKeySpec作为Triple DES密钥的透明表示。

Android提供了以下 SecretKeyFactory算法:

Name Supported (API Levels)
AES 23+
DES 1+
DESede 1+
HmacSHA1 23+
HmacSHA224 23+
HmacSHA256 23+
HmacSHA384 23+
HmacSHA512 23+
PBEwithHmacSHA1 1+
PBEwithMD5and128BITAES-CBC-OPENSSL 1+
PBEwithMD5and192BITAES-CBC-OPENSSL 1+
PBEwithMD5and256BITAES-CBC-OPENSSL 1+
PBEwithMD5andDES 1+
PBEwithMD5andRC2 1+
PBEwithSHA1andDES 1+
PBEwithSHA1andRC2 1+
PBEwithSHA256and128BITAES-CBC-BC 1+
PBEwithSHA256and192BITAES-CBC-BC 1+
PBEwithSHA256and256BITAES-CBC-BC 1+
PBEwithSHAand128BITAES-CBC-BC 1+
PBEwithSHAand128BITRC2-CBC 10+
PBEwithSHAand128BITRC4 10+
PBEwithSHAand192BITAES-CBC-BC 1+
PBEwithSHAand2-KEYTRIPLEDES-CBC 1+
PBEwithSHAand256BITAES-CBC-BC 1+
PBEwithSHAand3-KEYTRIPLEDES-CBC 1+
PBEwithSHAand40BITRC2-CBC 1+
PBEwithSHAand40BITRC4 10+
PBEwithSHAandTWOFISH-CBC 10+
PBKDF2withHmacSHA1 10+
PBKDF2withHmacSHA1and8BIT 19+
These algorithms are described in the SecretKeyFactory section of the Java Cryptography Architecture Standard Algorithm Name Documentation.

也可以看看:

Summary

Protected constructors

SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)

创建一个SecretKeyFactory对象。

Public methods

final SecretKey generateSecret(KeySpec keySpec)

根据提供的密钥规范(密钥材料)生成一个 SecretKey对象。

final String getAlgorithm()

返回此 SecretKeyFactory对象的算法名称。

static final SecretKeyFactory getInstance(String algorithm)

返回转换指定算法的密钥的 SecretKeyFactory对象。

static final SecretKeyFactory getInstance(String algorithm, String provider)

返回转换指定算法的密钥的 SecretKeyFactory对象。

static final SecretKeyFactory getInstance(String algorithm, Provider provider)

返回转换指定算法的密钥的 SecretKeyFactory对象。

final KeySpec getKeySpec(SecretKey key, Class keySpec)

以请求的格式返回给定键对象的规范(键材料)。

final Provider getProvider()

返回此 SecretKeyFactory对象的提供者。

final SecretKey translateKey(SecretKey key)

将提供者可能未知或可能不可信的密钥对象转换为此密钥工厂的相应密钥对象。

Inherited methods

From class java.lang.Object

Protected constructors

SecretKeyFactory

Added in API level 1
SecretKeyFactory (SecretKeyFactorySpi keyFacSpi, 
                Provider provider, 
                String algorithm)

创建一个SecretKeyFactory对象。

Parameters
keyFacSpi SecretKeyFactorySpi: the delegate
provider Provider: the provider
algorithm String: the secret-key algorithm

Public methods

generateSecret

Added in API level 1
SecretKey generateSecret (KeySpec keySpec)

从提供的密钥规范(密钥材料)中生成一个 SecretKey对象。

Parameters
keySpec KeySpec: the specification (key material) of the secret key
Returns
SecretKey the secret key
Throws
InvalidKeySpecException if the given key specification is inappropriate for this secret-key factory to produce a secret key.

getAlgorithm

Added in API level 1
String getAlgorithm ()

返回此 SecretKeyFactory对象的算法名称。

这与在创建此 SecretKeyFactory对象的 getInstance调用之一中指定的名称相同。

Returns
String the algorithm name of this SecretKeyFactory object.

getInstance

Added in API level 1
SecretKeyFactory getInstance (String algorithm)

返回转换指定算法的密钥的 SecretKeyFactory对象。

该方法遍历注册安全提供程序的列表,从最优先的提供程序开始。 返回一个新的SecretKeyFactory对象,它封装来自支持指定算法的第一个Provider的SecretKeyFactorySpi实现。

请注意,注册供应商列表可能通过 Security.getProviders()方法检索。

Parameters
algorithm String: the standard name of the requested secret-key algorithm. See the SecretKeyFactory section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard algorithm names.
Returns
SecretKeyFactory the new SecretKeyFactory object.
Throws
NullPointerException if the specified algorithm is null.
NoSuchAlgorithmException if no Provider supports a SecretKeyFactorySpi implementation for the specified algorithm.

也可以看看:

getInstance

Added in API level 1
SecretKeyFactory getInstance (String algorithm, 
                String provider)

返回转换指定算法的密钥的 SecretKeyFactory对象。

返回一个新的SecretKeyFactory对象,封装来自指定提供者的SecretKeyFactorySpi实现。 指定的提供者必须在安全提供者列表中注册。

请注意,可以通过 Security.getProviders()方法检索注册供应商列表。

Parameters
algorithm String: the standard name of the requested secret-key algorithm. See the SecretKeyFactory section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard algorithm names.
provider String: the name of the provider.
Returns
SecretKeyFactory the new SecretKeyFactory object.
Throws
NoSuchAlgorithmException if a SecretKeyFactorySpi implementation for the specified algorithm is not available from the specified provider.
NullPointerException if the specified algorithm is null.
NoSuchProviderException if the specified provider is not registered in the security provider list.
IllegalArgumentException if the provider is null or empty.

也可以看看:

getInstance

Added in API level 1
SecretKeyFactory getInstance (String algorithm, 
                Provider provider)

返回转换指定算法的密钥的 SecretKeyFactory对象。

返回一个新的SecretKeyFactory对象,它封装了指定Provider对象的SecretKeyFactorySpi实现。 请注意,指定的Provider对象不必在提供程序列表中注册。

Parameters
algorithm String: the standard name of the requested secret-key algorithm. See the SecretKeyFactory section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard algorithm names.
provider Provider: the provider.
Returns
SecretKeyFactory the new SecretKeyFactory object.
Throws
NullPointerException if the specified algorithm is null.
NoSuchAlgorithmException if a SecretKeyFactorySpi implementation for the specified algorithm is not available from the specified Provider object.
IllegalArgumentException if the provider is null.

也可以看看:

getKeySpec

Added in API level 1
KeySpec getKeySpec (SecretKey key, 
                Class keySpec)

以请求的格式返回给定键对象的规范(键材料)。

Parameters
key SecretKey: the key
keySpec Class: the requested format in which the key material shall be returned
Returns
KeySpec the underlying key specification (key material) in the requested format
Throws
InvalidKeySpecException if the requested key specification is inappropriate for the given key (e.g., the algorithms associated with key and keySpec do not match, or key references a key on a cryptographic hardware device whereas keySpec is the specification of a software-based key), or the given key cannot be dealt with (e.g., the given key has an algorithm or format not supported by this secret-key factory).

getProvider

Added in API level 1
Provider getProvider ()

返回此 SecretKeyFactory对象的提供者。

Returns
Provider the provider of this SecretKeyFactory object

translateKey

Added in API level 1
SecretKey translateKey (SecretKey key)

将提供者可能未知或可能不可信的密钥对象转换为此密钥工厂的相应密钥对象。

Parameters
key SecretKey: the key whose provider is unknown or untrusted
Returns
SecretKey the translated key
Throws
InvalidKeyException if the given key cannot be processed by this secret-key factory.

Hooray!