Top Description Fields Constructors Methods
sun.security.pkcs11

pack-priv final Class P11KeyGenerator

extends KeyGeneratorSpi
Class Inheritance
Imports
java.security.*, java.security.spec.AlgorithmParameterSpec, javax.crypto.*, sun.security.util.SecurityProviderConstants, sun.security.pkcs11.wrapper.*

KeyGenerator implementation class. This class currently supports DES, DESede, AES, ARCFOUR, Blowfish, Hmac using MD5, SHA, SHA-2 family (SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256), and SHA-3 family (SHA3-224, SHA3-256, SHA3-384, SHA3-512) of digests.
Author
Andreas Sterbenz
Since
1.5

Field Summary

Modifier and TypeField and Description
private final String
private int
private long
private long
private final CK_MECHANISM_INFO
private int
private boolean
private final Token

Constructor Summary

AccessConstructor and Description
pack-priv
P11KeyGenerator(Token token, String algorithm, long mechanism)

Method Summary

Modifier and TypeMethod and Description
private static int
pack-priv static int

Returns:

the significant key size (in bits) corresponding to the specified key size.
checkKeySize
(long
the PKCS#11 key generation mechanism.
keyGenMech
,
int
the to-be-checked key size for this mechanism.
keySize
,
Token
token which provides this mechanism.
token
)

Utility method for checking if the specified key size is valid and within the supported range.

private static int
checkKeySize(long keyGenMech, int keySize, CK_MECHANISM_INFO range)

protected SecretKey
engineGenerateKey()

Implements abstract javax.crypto.KeyGeneratorSpi.engineGenerateKey.

Generates a secret key.

protected void
engineInit(SecureRandom
the source of randomness for this generator
random
)

Implements abstract javax.crypto.KeyGeneratorSpi.engineInit.

Initializes the key generator.

protected void
engineInit(AlgorithmParameterSpec
the key generation parameters
params
,
SecureRandom
the source of randomness for this key generator
random
)

Implements abstract javax.crypto.KeyGeneratorSpi.engineInit.

Initializes the key generator with the specified parameter set and a user-provided source of randomness.

protected void
engineInit(int
the keysize. This is an algorithm-specific metric, specified in number of bits.
keySize
,
SecureRandom
the source of randomness for this key generator
random
)

Implements abstract javax.crypto.KeyGeneratorSpi.engineInit.

Initializes this key generator for a certain keysize, using the given source of randomness.

private static CK_MECHANISM_INFO
getSupportedRange(Token token, long mech)

private void

Field Detail

algorithmback to summary
private final String algorithm
keySizeback to summary
private int keySize
keyTypeback to summary
private long keyType
mechanismback to summary
private long mechanism
rangeback to summary
private final CK_MECHANISM_INFO range
significantKeySizeback to summary
private int significantKeySize
supportBothKeySizesback to summary
private boolean supportBothKeySizes
tokenback to summary
private final Token token

Constructor Detail

P11KeyGeneratorback to summary
pack-priv P11KeyGenerator(Token token, String algorithm, long mechanism) throws PKCS11Exception

Method Detail

adjustKeySizeback to summary
private static int adjustKeySize(int ks, CK_MECHANISM_INFO mi)
checkKeySizeback to summary
pack-priv static int checkKeySize(long keyGenMech, int keySize, Token token) throws InvalidAlgorithmParameterException, ProviderException

Utility method for checking if the specified key size is valid and within the supported range. Return the significant key size upon successful validation.

Parameters
keyGenMech:long

the PKCS#11 key generation mechanism.

keySize:int

the to-be-checked key size for this mechanism.

token:Token

token which provides this mechanism.

Returns:int

the significant key size (in bits) corresponding to the specified key size.

Exceptions
ProviderException:
if this mechanism isn't supported by SunPKCS11 or underlying native impl.
InvalidParameterException:
if the specified key size is invalid.
checkKeySizeback to summary
private static int checkKeySize(long keyGenMech, int keySize, CK_MECHANISM_INFO range) throws InvalidAlgorithmParameterException
engineGenerateKeyback to summary
protected SecretKey engineGenerateKey()

Implements abstract javax.crypto.KeyGeneratorSpi.engineGenerateKey.

Doc from javax.crypto.KeyGeneratorSpi.engineGenerateKey.

Generates a secret key.

Returns:SecretKey

the new key

engineInitback to summary
protected void engineInit(SecureRandom random)

Implements abstract javax.crypto.KeyGeneratorSpi.engineInit.

Doc from javax.crypto.KeyGeneratorSpi.engineInit.

Initializes the key generator.

Parameters
random:SecureRandom

the source of randomness for this generator

engineInitback to summary
protected void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException

Implements abstract javax.crypto.KeyGeneratorSpi.engineInit.

Doc from javax.crypto.KeyGeneratorSpi.engineInit.

Initializes the key generator with the specified parameter set and a user-provided source of randomness.

Parameters
params:AlgorithmParameterSpec

the key generation parameters

random:SecureRandom

the source of randomness for this key generator

Exceptions
InvalidAlgorithmParameterException:
if params is inappropriate for this key generator
engineInitback to summary
protected void engineInit(int keySize, SecureRandom random)

Implements abstract javax.crypto.KeyGeneratorSpi.engineInit.

Doc from javax.crypto.KeyGeneratorSpi.engineInit.

Initializes this key generator for a certain keysize, using the given source of randomness.

Parameters
keySize:int

the keysize. This is an algorithm-specific metric, specified in number of bits.

random:SecureRandom

the source of randomness for this key generator

getSupportedRangeback to summary
private static CK_MECHANISM_INFO getSupportedRange(Token token, long mech) throws ProviderException
setDefaultback to summary
private void setDefault()