Name
SecretKeyFactory
Synopsis
This class defines an API for
translating a secret key between its opaque
SecretKey
representation and its transparent
javax.crypto.SecretKeySpec
representation. It is
much like java.security.KeyFactory
, except that it
works with secret (or symmetric) keys rather than with public and
private (asymmetric) keys. SecretKeyFactory
is
algorithm-independent and provider-based, so you must obtain a
SecretKeyFactory
object by calling one of the
static getInstance( )
factory methods and
specifying the name of the desired secret-key algorithm and,
optionally, the name of the provider whose implementation is desired.
In Java
5.0, the “SunJCE” provider provides
SecretKeyFactory
implementations for algorithms
with the following names:
DES |
DESede |
PBE |
PBEWithMD5AndDES |
PBEWithMD5AndTripleDES |
PBEWithSHA1AndDESede |
PBEWithSHA1AndRC2 |
Once you have obtained a
SecretKeyFactory
, use generateSecret(
)
to create a SecretKey
from a
java.security.spec.KeySpec
(or its subclass,
javax.crypto.spec.SecretKeySpec
). Or call
getKeySpec( )
to obtain a
KeySpec
for a Key
object.
Because there can be more than one suitable type of
KeySpec
, getKeySpec( )
requires
a Class
object to specify the type of the
KeySpec
to be created. See also
DESKeySpec
, DESedeKeySpec
, and
PBEKeySpec
in the
javax.crypto.spec
package.
public class SecretKeyFactory { // Protected Constructors protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, java.security.Provider provider, String algorithm); ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.