Stay organized with collections
Save and categorize content based on your preferences.
KeyPairGeneratorSpi
abstract class KeyPairGeneratorSpi
Known Direct Subclasses
KeyPairGenerator |
The KeyPairGenerator class is used to generate pairs of public and private keys.
|
|
This class defines the Service Provider Interface (SPI) for the KeyPairGenerator
class, which is used to generate pairs of public and private keys.
All the abstract methods in this class must be implemented by each cryptographic service provider who wishes to supply the implementation of a key pair generator for a particular algorithm.
In case the client does not explicitly initialize the KeyPairGenerator (via a call to an initialize
method), each provider must supply (and document) a default initialization. For example, the Sun provider uses a default modulus size (keysize) of 1024 bits.
Summary
Public methods |
abstract KeyPair! |
Generates a key pair.
|
abstract Unit |
Initializes the key pair generator for a certain keysize, using the default parameter set.
|
open Unit |
Initializes the key pair generator using the specified parameter set and user-provided source of randomness.
|
Public constructors
KeyPairGeneratorSpi
KeyPairGeneratorSpi()
Public methods
generateKeyPair
abstract fun generateKeyPair(): KeyPair!
Generates a key pair. Unless an initialization method is called using a KeyPairGenerator interface, algorithm-specific defaults will be used. This will generate a new key pair every time it is called.
Return |
KeyPair! |
the newly generated KeyPair |
initialize
abstract fun initialize(
keysize: Int,
random: SecureRandom!
): Unit
Initializes the key pair generator for a certain keysize, using the default parameter set.
Parameters |
keysize |
Int: the keysize. This is an algorithm-specific metric, such as modulus length, specified in number of bits. |
random |
SecureRandom!: the source of randomness for this generator. |
Exceptions |
java.security.InvalidParameterException |
if the keysize is not supported by this KeyPairGeneratorSpi object. |
initialize
open fun initialize(
params: AlgorithmParameterSpec!,
random: SecureRandom!
): Unit
Initializes the key pair generator using the specified parameter set and user-provided source of randomness.
This concrete method has been added to this previously-defined abstract class. (For backwards compatibility, it cannot be abstract.) It may be overridden by a provider to initialize the key pair generator. Such an override is expected to throw an InvalidAlgorithmParameterException if a parameter is inappropriate for this key pair generator. If this method is not overridden, it always throws an UnsupportedOperationException.
Exceptions |
java.security.InvalidAlgorithmParameterException |
if the given parameters are inappropriate for this key pair 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,["# KeyPairGeneratorSpi\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nKeyPairGeneratorSpi\n===================\n\n```\nabstract class KeyPairGeneratorSpi\n```\n\n|---|----------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [java.security.KeyPairGeneratorSpi](#) |\n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [KeyPairGenerator](/reference/kotlin/java/security/KeyPairGenerator) |----------------------------------------------------------------------|----------------------------------------------------------------------------------| | [KeyPairGenerator](/reference/kotlin/java/security/KeyPairGenerator) | The KeyPairGenerator class is used to generate pairs of public and private keys. | |\n\nThis class defines the *Service Provider Interface* (**SPI** ) for the `KeyPairGenerator` class, which is used to generate pairs of public and private keys.\n\nAll the abstract methods in this class must be implemented by each cryptographic service provider who wishes to supply the implementation of a key pair generator for a particular algorithm.\n\nIn case the client does not explicitly initialize the KeyPairGenerator (via a call to an `initialize` method), each provider must supply (and document) a default initialization. For example, the *Sun* provider uses a default modulus size (keysize) of 1024 bits.\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------------------------------|---|\n| [KeyPairGeneratorSpi](#KeyPairGeneratorSpi())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [KeyPair](/reference/kotlin/java/security/KeyPair)! | [generateKeyPair](#generateKeyPair())`()` Generates a key pair. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [initialize](#initialize(kotlin.Int,%20java.security.SecureRandom))`(`keysize:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `random:` `[SecureRandom](/reference/kotlin/java/security/SecureRandom)!`)` Initializes the key pair generator for a certain keysize, using the default parameter set. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [initialize](#initialize(java.security.spec.AlgorithmParameterSpec,%20java.security.SecureRandom))`(`params:` `[AlgorithmParameterSpec](/reference/kotlin/java/security/spec/AlgorithmParameterSpec)!`, `random:` `[SecureRandom](/reference/kotlin/java/security/SecureRandom)!`)` Initializes the key pair generator using the specified parameter set and user-provided source of randomness. |\n\nPublic constructors\n-------------------\n\n### KeyPairGeneratorSpi\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nKeyPairGeneratorSpi()\n```\n\nPublic methods\n--------------\n\n### generateKeyPair\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun generateKeyPair(): KeyPair!\n```\n\nGenerates a key pair. Unless an initialization method is called using a KeyPairGenerator interface, algorithm-specific defaults will be used. This will generate a new key pair every time it is called.\n\n| Return ||\n|-----------------------------------------------------|-------------------------------|\n| [KeyPair](/reference/kotlin/java/security/KeyPair)! | the newly generated `KeyPair` |\n\n### initialize\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun initialize(\n keysize: Int, \n random: SecureRandom!\n): Unit\n```\n\nInitializes the key pair generator for a certain keysize, using the default parameter set.\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, such as modulus length, specified in number of bits. |\n| `random` | [SecureRandom](/reference/kotlin/java/security/SecureRandom)!: the source of randomness for this generator. |\n\n| Exceptions ||\n|-------------------------------------------|-----------------------------------------------------------------------|\n| `java.security.InvalidParameterException` | if the `keysize` is not supported by this KeyPairGeneratorSpi object. |\n\n### initialize\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun initialize(\n params: AlgorithmParameterSpec!, \n random: SecureRandom!\n): Unit\n```\n\nInitializes the key pair generator using the specified parameter set and user-provided source of randomness.\n\nThis concrete method has been added to this previously-defined abstract class. (For backwards compatibility, it cannot be abstract.) It may be overridden by a provider to initialize the key pair generator. Such an override is expected to throw an InvalidAlgorithmParameterException if a parameter is inappropriate for this key pair generator. If this method is not overridden, it always throws an UnsupportedOperationException.\n\n| Parameters ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------|\n| `params` | [AlgorithmParameterSpec](/reference/kotlin/java/security/spec/AlgorithmParameterSpec)!: the parameter set used to generate the keys. |\n| `random` | [SecureRandom](/reference/kotlin/java/security/SecureRandom)!: the source of randomness for this generator. |\n\n| Exceptions ||\n|----------------------------------------------------|------------------------------------------------------------------------|\n| `java.security.InvalidAlgorithmParameterException` | if the given parameters are inappropriate for this key pair generator. |"]]