public final class PasswordFactory extends Object
Password factories are used to handle and manipulate password objects and their corresponding
password specifications. Passwords are a kind of key which are used to store and compare against a
string of text entered by a human. Passwords can be one-way (OneWayPassword
) or two-way
(TwoWayPassword
).
Constructor and Description |
---|
PasswordFactory(PasswordFactorySpi spi,
Provider provider,
String algorithm)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
<T extends KeySpec> |
convertibleToKeySpec(Password password,
Class<T> specType)
Determine whether the given password can be converted to the given key specification type by this factory.
|
Password |
generatePassword(KeySpec keySpec)
Generate a new
Password object for the given specification. |
String |
getAlgorithm()
Get the algorithm of this password factory.
|
static PasswordFactory |
getInstance(String algorithm)
Get a password factory instance.
|
static PasswordFactory |
getInstance(String algorithm,
Provider provider)
Get a password factory instance.
|
static PasswordFactory |
getInstance(String algorithm,
String providerName)
Get a password factory instance.
|
static PasswordFactory |
getInstance(String algorithm,
Supplier<Provider[]> providerSupplier)
Get a password factory instance.
|
<T extends KeySpec> |
getKeySpec(Password password,
Class<T> specType)
Generate a key specification of the given type from the given password object.
|
Provider |
getProvider()
Get the provider of this password factory.
|
boolean |
isTranslatable(Password password)
Determine whether the given password can be translated into one which is consumable by this factory.
|
Password |
transform(Password password,
AlgorithmParameterSpec parameterSpec)
Transform a password with new parameters.
|
Password |
translate(Password password)
Translate the given password object to one which is consumable by this factory.
|
boolean |
verify(Password password,
char[] guess)
Verify a password guess.
|
public PasswordFactory(PasswordFactorySpi spi, Provider provider, String algorithm)
spi
- the password factory SPI (not null
)provider
- the provider (not null
)algorithm
- the algorithm name (not null
)public static PasswordFactory getInstance(String algorithm) throws NoSuchAlgorithmException
algorithm
- the name of the algorithmNoSuchAlgorithmException
- if the given algorithm has no available implementationspublic static PasswordFactory getInstance(String algorithm, String providerName) throws NoSuchAlgorithmException, NoSuchProviderException
algorithm
- the name of the algorithmproviderName
- the name of the provider to useNoSuchAlgorithmException
- if the given algorithm has no available implementationsNoSuchProviderException
public static PasswordFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
algorithm
- the name of the algorithmprovider
- the provider to useNoSuchAlgorithmException
- if the given algorithm has no available implementationspublic static PasswordFactory getInstance(String algorithm, Supplier<Provider[]> providerSupplier) throws NoSuchAlgorithmException
algorithm
- the name of the algorithmproviderSupplier
- the provider supplier to searchNoSuchAlgorithmException
- if the given algorithm has no available implementationspublic Provider getProvider()
public String getAlgorithm()
public Password generatePassword(KeySpec keySpec) throws InvalidKeySpecException
Password
object for the given specification.keySpec
- the specificationInvalidKeySpecException
- if the key specification is not valid for this algorithmpublic <T extends KeySpec> T getKeySpec(Password password, Class<T> specType) throws InvalidKeySpecException
T
- the specification typepassword
- the password objectspecType
- the specification classInvalidKeySpecException
- if the password cannot be translated to the given key specification typepublic <T extends KeySpec> boolean convertibleToKeySpec(Password password, Class<T> specType)
T
- the specification typepassword
- the password objectspecType
- the specification classtrue
if the password can be converted, false
otherwisepublic boolean isTranslatable(Password password)
true
, then translate(Password)
will succeed.password
- the password objecttrue
if the given password is supported by this algorithm, false
otherwisepublic Password translate(Password password) throws InvalidKeyException
password
- the password objectInvalidKeyException
- if the given password is not supported by this algorithmpublic boolean verify(Password password, char[] guess) throws InvalidKeyException
password
- the password objectguess
- the guessed password characterstrue
if the guess matches the password, false
otherwiseInvalidKeyException
- if the given password is not supported by this factorypublic Password transform(Password password, AlgorithmParameterSpec parameterSpec) throws InvalidKeyException, InvalidAlgorithmParameterException
password
- the passwordparameterSpec
- the new parametersInvalidKeyException
- if the given password is invalidInvalidAlgorithmParameterException
- if the transformation cannot be applied to the given parametersCopyright © 2018 JBoss by Red Hat. All rights reserved.