Package org.mozilla.jss.pkcs11
Class PK11KeyGenerator
- java.lang.Object
-
- org.mozilla.jss.pkcs11.PK11KeyGenerator
-
- All Implemented Interfaces:
KeyGenerator
public final class PK11KeyGenerator extends java.lang.Object implements KeyGenerator
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.mozilla.jss.crypto.KeyGenerator
KeyGenerator.CharToByteConverter
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SymmetricKey
clone(SymmetricKey key)
Allows a SymmetricKey to be cloned on a different token.static SymmetricKey
clone(SymmetricKey key, PK11Token token)
Allows a SymmetricKey to be cloned on a different token.SymmetricKey
generate()
Generates the key.byte[]
generatePBE_IV()
Generates an Initialization Vector using a PBE algorithm.void
initialize(int strength)
void
initialize(java.security.spec.AlgorithmParameterSpec parameters)
void
sensitiveKeys(boolean sensitive)
Tells the generator to generate sensitive or insensitive keys.void
setCharToByteConverter(KeyGenerator.CharToByteConverter charToByte)
Sets the character to byte converter for passwords.void
setKeyUsages(long opFlags)
void
setKeyUsages(SymmetricKey.Usage[] usages)
void
temporaryKeys(boolean temp)
Tells the generator to generate temporary or permanent keys.
-
-
-
Method Detail
-
setCharToByteConverter
public void setCharToByteConverter(KeyGenerator.CharToByteConverter charToByte)
Sets the character to byte converter for passwords. The default conversion is UTF8 with no null termination.- Specified by:
setCharToByteConverter
in interfaceKeyGenerator
- Parameters:
charToByte
- Character-to-byte converter.
-
initialize
public void initialize(int strength) throws java.security.InvalidAlgorithmParameterException
- Specified by:
initialize
in interfaceKeyGenerator
- Parameters:
strength
- Key size in bits. Must be evenly divisible by 8.- Throws:
java.security.InvalidAlgorithmParameterException
- If parameter is invalid.
-
initialize
public void initialize(java.security.spec.AlgorithmParameterSpec parameters) throws java.security.InvalidAlgorithmParameterException
- Specified by:
initialize
in interfaceKeyGenerator
- Throws:
java.security.InvalidAlgorithmParameterException
-
setKeyUsages
public void setKeyUsages(SymmetricKey.Usage[] usages)
- Specified by:
setKeyUsages
in interfaceKeyGenerator
- Parameters:
usages
- The operations the key will be used for after it is generated. You have to specify these so that the key can be properly marked with the operations it supports. Some PKCS #11 tokens require that a key be marked for an operation before it can perform that operation. The default is SymmetricKey.Usage.SIGN and SymmetricKey.Usage.ENCRYPT.
-
setKeyUsages
public void setKeyUsages(long opFlags)
-
temporaryKeys
public void temporaryKeys(boolean temp)
Description copied from interface:KeyGenerator
Tells the generator to generate temporary or permanent keys. Temporary keys are not written permanently to the token. They are destroyed by the garbage collector. If this method is not called, the default is temporary keys.- Specified by:
temporaryKeys
in interfaceKeyGenerator
- Parameters:
temp
- True to generate temporary key.
-
sensitiveKeys
public void sensitiveKeys(boolean sensitive)
Description copied from interface:KeyGenerator
Tells the generator to generate sensitive or insensitive keys. Certain attributes of a sensitive key cannot be revealed in plaintext outside the token. If this method is not called, the default is token dependent.- Specified by:
sensitiveKeys
in interfaceKeyGenerator
- Parameters:
sensitive
- True to generate sensitive.
-
generate
public SymmetricKey generate() throws java.lang.IllegalStateException, TokenException, java.io.CharConversionException
Generates the key. This is the public interface, the actual work is done by native methods.- Specified by:
generate
in interfaceKeyGenerator
- Returns:
- Symmetric key.
- Throws:
java.lang.IllegalStateException
- If key generation failed.TokenException
- If an error occurred in the token.java.io.CharConversionException
- If an encoding error occurred.
-
generatePBE_IV
public byte[] generatePBE_IV() throws TokenException, java.io.CharConversionException
Generates an Initialization Vector using a PBE algorithm. In order to call this method, the algorithm must be a PBE algorithm, and the KeyGenerator must have been initialized with an instance ofPBEKeyGenParams
.- Specified by:
generatePBE_IV
in interfaceKeyGenerator
- Returns:
- The initialization vector derived from the password and salt using the PBE algorithm.
- Throws:
TokenException
- If an error occurs on the CryptoToken while generating the IV.java.io.CharConversionException
- If an encoding error occurred.
-
clone
public SymmetricKey clone(SymmetricKey key) throws SymmetricKey.NotExtractableException, java.security.InvalidKeyException, TokenException
Allows a SymmetricKey to be cloned on a different token.- Specified by:
clone
in interfaceKeyGenerator
- Parameters:
key
- Symmetric key.- Returns:
- Cloned symmetric key.
- Throws:
SymmetricKey.NotExtractableException
- If the key material cannot be extracted from the current token.java.security.InvalidKeyException
- If the owning token cannot process the key to be cloned.TokenException
- If an error occurred in the token.
-
clone
public static SymmetricKey clone(SymmetricKey key, PK11Token token) throws SymmetricKey.NotExtractableException, java.security.InvalidKeyException, TokenException
Allows a SymmetricKey to be cloned on a different token.- Parameters:
key
- The key to clone.token
- The token on which to clone the key.- Throws:
SymmetricKey.NotExtractableException
- If the key material cannot be extracted from the current token.java.security.InvalidKeyException
- If the owning token cannot process the key to be cloned.TokenException
-
-