Package org.mozilla.jss.crypto
Interface KeyGenerator
- All Known Implementing Classes:
PK11KeyGenerator
public interface KeyGenerator
Generates symmetric keys for encryption and decryption.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
An interface for converting a password of Java characters into an array of bytes. -
Method Summary
Modifier and TypeMethodDescriptionclone
(SymmetricKey key) Allows a SymmetricKey to be cloned on a different token.generate()
Generates a symmetric key.byte[]
Generates an Initialization Vector using a PBE algorithm.void
initialize
(int strength) void
initialize
(AlgorithmParameterSpec parameters) void
sensitiveKeys
(boolean sensitive) Tells the generator to generate sensitive or insensitive keys.void
Sets the character to byte converter for passwords.void
setKeyUsages
(SymmetricKey.Usage[] usages) void
temporaryKeys
(boolean temp) Tells the generator to generate temporary or permanent keys.
-
Method Details
-
initialize
- Parameters:
strength
- Key size in bits. Must be evenly divisible by 8.- Throws:
InvalidAlgorithmParameterException
- If parameter is invalid.
-
initialize
-
setKeyUsages
- 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.
-
temporaryKeys
void temporaryKeys(boolean temp) 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.- Parameters:
temp
- True to generate temporary key.
-
sensitiveKeys
void sensitiveKeys(boolean sensitive) 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.- Parameters:
sensitive
- True to generate sensitive.
-
generate
Generates a symmetric key.- Returns:
- Symmetric key.
- Throws:
IllegalStateException
- If key generation failed.TokenException
- If an error occurred in the token.CharConversionException
- If an encoding error occurred.
-
generatePBE_IV
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
.- Returns:
- The initialization vector derived from the password and salt using the PBE algorithm.
- Throws:
IllegalStateException
- If the algorithm is not a PBE algorithm, or the KeyGenerator has not been initialized with an instance ofPBEKeyGenParams
.TokenException
- If an error occurs on the CryptoToken while generating the IV.CharConversionException
- If an encoding error occurred.
-
clone
SymmetricKey clone(SymmetricKey key) throws SymmetricKey.NotExtractableException, InvalidKeyException, TokenException Allows a SymmetricKey to be cloned on a different token.- Parameters:
key
- Symmetric key.- Returns:
- Cloned symmetric key.
- Throws:
SymmetricKey.NotExtractableException
- If the key material cannot be extracted from the current token.InvalidKeyException
- If the owning token cannot process the key to be cloned.TokenException
- If an error occurred in the token.
-
setCharToByteConverter
Sets the character to byte converter for passwords. The default conversion is UTF8 with no null termination.- Parameters:
charToByte
- Character-to-byte converter.
-