Stay organized with collections
Save and categorize content based on your preferences.
KeyGeneratorSpi
abstract class KeyGeneratorSpi
This class defines the Service Provider Interface (SPI) for the KeyGenerator
class. All the abstract methods in this class must be implemented by each cryptographic service provider who wishes to supply the implementation of a key generator for a particular algorithm.
Summary
Protected methods |
abstract SecretKey! |
Generates a secret key.
|
abstract Unit |
Initializes this key generator for a certain keysize, using the given source of randomness.
|
abstract Unit |
Initializes the key generator.
|
abstract Unit |
Initializes the key generator with the specified parameter set and a user-provided source of randomness.
|
Public constructors
KeyGeneratorSpi
KeyGeneratorSpi()
Protected methods
engineGenerateKey
protected abstract fun engineGenerateKey(): SecretKey!
Generates a secret key.
engineInit
protected abstract fun engineInit(
keysize: Int,
random: SecureRandom!
): Unit
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 |
Exceptions |
java.security.InvalidParameterException |
if the keysize is wrong or not supported. |
engineInit
protected abstract fun engineInit(random: SecureRandom!): Unit
Initializes the key generator.
Parameters |
random |
SecureRandom!: the source of randomness for this generator |
engineInit
protected abstract fun engineInit(
params: AlgorithmParameterSpec!,
random: SecureRandom!
): Unit
Initializes the key generator with the specified parameter set and a user-provided source of randomness.
Exceptions |
java.security.InvalidAlgorithmParameterException |
if params is inappropriate for this key generator |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# KeyGeneratorSpi\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nKeyGeneratorSpi\n===============\n\n```\nabstract class KeyGeneratorSpi\n```\n\n|---|-----------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [javax.crypto.KeyGeneratorSpi](#) |\n\nThis class defines the *Service Provider Interface* (**SPI** ) for the `KeyGenerator` class. All the abstract methods in this class must be implemented by each cryptographic service provider who wishes to supply the implementation of a key generator for a particular algorithm.\n\nSummary\n-------\n\n| Public constructors ||\n|--------------------------------------------------|---|\n| [KeyGeneratorSpi](#KeyGeneratorSpi())`()` \u003cbr /\u003e |\n\n| Protected methods ||\n|---------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [SecretKey](/reference/kotlin/javax/crypto/SecretKey)! | [engineGenerateKey](#engineGenerateKey())`()` Generates a secret key. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [engineInit](#engineInit(kotlin.Int,%20java.security.SecureRandom))`(`keysize:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `random:` `[SecureRandom](../../java/security/SecureRandom.html#)!`)` Initializes this key generator for a certain keysize, using the given source of randomness. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [engineInit](#engineInit(java.security.SecureRandom))`(`random:` `[SecureRandom](../../java/security/SecureRandom.html#)!`)` Initializes the key generator. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [engineInit](#engineInit(java.security.spec.AlgorithmParameterSpec,%20java.security.SecureRandom))`(`params:` `[AlgorithmParameterSpec](../../java/security/spec/AlgorithmParameterSpec.html#)!`, `random:` `[SecureRandom](../../java/security/SecureRandom.html#)!`)` Initializes the key generator with the specified parameter set and a user-provided source of randomness. |\n\nPublic constructors\n-------------------\n\n### KeyGeneratorSpi\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nKeyGeneratorSpi()\n```\n\nProtected methods\n-----------------\n\n### engineGenerateKey\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected abstract fun engineGenerateKey(): SecretKey!\n```\n\nGenerates a secret key.\n\n| Return ||\n|--------------------------------------------------------|-------------|\n| [SecretKey](/reference/kotlin/javax/crypto/SecretKey)! | the new key |\n\n### engineInit\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected abstract fun engineInit(\n keysize: Int, \n random: SecureRandom!\n): Unit\n```\n\nInitializes this key generator for a certain keysize, using the given source of randomness.\n\n| Parameters ||\n|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `keysize` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): the keysize. This is an algorithm-specific metric, specified in number of bits. |\n| `random` | [SecureRandom](../../java/security/SecureRandom.html#)!: the source of randomness for this key generator |\n\n| Exceptions ||\n|-------------------------------------------|-------------------------------------------|\n| `java.security.InvalidParameterException` | if the keysize is wrong or not supported. |\n\n### engineInit\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected abstract fun engineInit(random: SecureRandom!): Unit\n```\n\nInitializes the key generator.\n\n| Parameters ||\n|----------|------------------------------------------------------------------------------------------------------|\n| `random` | [SecureRandom](../../java/security/SecureRandom.html#)!: the source of randomness for this generator |\n\n### engineInit\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected abstract fun engineInit(\n params: AlgorithmParameterSpec!, \n random: SecureRandom!\n): Unit\n```\n\nInitializes the key generator with the specified parameter set and a user-provided source of randomness.\n\n| Parameters ||\n|----------|-----------------------------------------------------------------------------------------------------------------|\n| `params` | [AlgorithmParameterSpec](../../java/security/spec/AlgorithmParameterSpec.html#)!: the key generation parameters |\n| `random` | [SecureRandom](../../java/security/SecureRandom.html#)!: the source of randomness for this key generator |\n\n| Exceptions ||\n|----------------------------------------------------|-----------------------------------------------------|\n| `java.security.InvalidAlgorithmParameterException` | if `params` is inappropriate for this key generator |"]]