Java Key Pair Generator Algorithms
The Java KeyPairGenerator class (java.security.KeyPairGenerator
) is used to generate asymmetric encryption / decryption key pairs. An asymmetric key pair consists of two keys. The first key is typically used to encrypt data. The second key which is used to decrypt data encrypted with the first key.
Getting the public key from the private key is in some algorithms just a matter of multiplication in the group of the elliptic curve. – Henry Oct 30 '13 at 6:53. Plz don't say no, I started the work, to proceed I need to generate public key. GetInstance(String algorithm) The getInstance method of java.security.KeyPairGenerator class is used to return a KeyPairGenerator object that generates public/private key pairs for the specified algorithm. This method traverses the list of registered security Providers, starting with the most preferred Provider.
Public Key, Private Key Type Key Pairs
The most commonly known type of asymmetric key pair is the public key, private key type of key pair. The private key is used to encrypt data, and the public key can be used to decrypt the data again. Actually, you could also encrypt data using the public key and decrypt it using the private key.
The private key is normally kept secret, and the public key can be made publicly available. Thus, if Jack encrypts some data with his private key, everyone in possession of Jack's public key can decrypt it.
Creating a KeyPairGenerator Instance
To use the Java KeyPairGenerator
you must first create a KeyPairGenerator
instance. Creating a KeyPairGenerator
instance is done by calling the method getInstance()
method. Here is an example of creating a Java KeyPairGenerator
instance:
The getInstance()
Photoshop cs6 license key generator mac. method takes the name of the encryption algorithm to generate the key pair for. In this example we use the name RSA
.
Initializing the KeyPairGenerator
Depending on the algorithm the key pair is generated for, you may have to initialize the KeyPairGenerator
instance. Initializing the KeyPairGenerator
is done by calling its initialize()
method. Here is an example of initializing a Java KeyPairGenerator
instance:
This example initializes the KeyPairGenerator
to generate keys of 2048 bits in size.
Generating a Key Pair
To generate a KeyPair
with a KeyPairGenerator
you call the generateKeyPair()
method. Here is an example of generating a KeyPair
with the KeyPairGenerator
:
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.
- See Also:
KeyPairGenerator
,AlgorithmParameterSpec
Constructor Summary |
---|
KeyPairGeneratorSpi() |
Method Summary | |
---|---|
abstract KeyPair | generateKeyPair() Generates a key pair. |
void | initialize(AlgorithmParameterSpec params, SecureRandom random) Initializes the key pair generator using the specified parameter set and user-provided source of randomness. |
abstract void | initialize(int keysize, SecureRandom random) Initializes the key pair generator for a certain keysize, using the default parameter set. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
KeyPairGeneratorSpi
Method Detail |
---|
initialize
- Initializes the key pair generator for a certain keysize, using the default parameter set.
- Parameters:
keysize
- the keysize. This is an algorithm-specific metric, such as modulus length, specified in number of bits.random
- the source of randomness for this generator.- Throws:
InvalidParameterException
- if thekeysize
is not supported by this KeyPairGeneratorSpi object.
initialize
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.
- Parameters:
params
- the parameter set used to generate the keys.random
- the source of randomness for this generator.- Throws:
InvalidAlgorithmParameterException
- if the given parameters are inappropriate for this key pair generator.- Since:
- 1.2
Java Key Pair Generator Algorithms Download
generateKeyPair
- 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.
- Returns:
- the newly generated KeyPair
Overview | Package | Class | Use | Tree | Deprecated | Index | Help |
Standard Ed. 6
Java Algorithms Examples
Submit a bug or featureFor further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java Algorithm Code
Copyright © 1993, 2011, Oracle and/or its affiliates. All rights reserved.