Sdílet prostřednictvím


KeyPairGenerator Class

Definition

The KeyPairGenerator class is used to generate pairs of public and private keys.

[Android.Runtime.Register("java/security/KeyPairGenerator", DoNotGenerateAcw=true)]
public abstract class KeyPairGenerator : Java.Security.KeyPairGeneratorSpi
[<Android.Runtime.Register("java/security/KeyPairGenerator", DoNotGenerateAcw=true)>]
type KeyPairGenerator = class
    inherit KeyPairGeneratorSpi
Inheritance
KeyPairGenerator
Attributes

Remarks

The KeyPairGenerator class is used to generate pairs of public and private keys. Key pair generators are constructed using the getInstance factory methods (static methods that return instances of a given class).

A Key pair generator for a particular algorithm creates a public/private key pair that can be used with this algorithm. It also associates algorithm-specific parameters with each of the generated keys.

There are two ways to generate a key pair: in an algorithm-independent manner, and in an algorithm-specific manner. The only difference between the two is the initialization of the object:

<ul> <li><b>Algorithm-Independent Initialization</b>

All key pair generators share the concepts of a keysize and a source of randomness. The keysize is interpreted differently for different algorithms (e.g., in the case of the DSA algorithm, the keysize corresponds to the length of the modulus). There is an #initialize(int, java.security.SecureRandom) initialize method in this KeyPairGenerator class that takes these two universally shared types of arguments. There is also one that takes just a keysize argument, and uses the SecureRandom implementation of the highest-priority installed provider as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness is used.)

Since no other parameters are specified when you call the above algorithm-independent initialize methods, it is up to the provider what to do about the algorithm-specific parameters (if any) to be associated with each of the keys.

If the algorithm is the DSA algorithm, and the keysize (modulus size) is 512, 768, 1024, or 2048, then the Sun provider uses a set of precomputed values for the p, q, and g parameters. If the modulus size is not one of the above values, the Sun provider creates a new set of parameters. Other providers might have precomputed parameter sets for more than just the modulus sizes mentioned above. Still others might not have a list of precomputed parameters at all and instead always create new parameter sets.

<li><b>Algorithm-Specific Initialization</b>

For situations where a set of algorithm-specific parameters already exists (e.g., so-called community parameters in DSA), there are two #initialize(java.security.spec.AlgorithmParameterSpec) initialize methods that have an AlgorithmParameterSpec argument. One also has a SecureRandom argument, while the other uses the SecureRandom implementation of the highest-priority installed provider as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness is used.) </ul>

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.

Note that this class is abstract and extends from KeyPairGeneratorSpi for historical reasons. Application developers should only take notice of the methods defined in this KeyPairGenerator class; all the methods in the superclass are intended for cryptographic service providers who wish to supply their own implementations of key pair generators.

Android provides the following KeyPairGenerator algorithms: <table> <thead> <tr> <th>Algorithm</th> <th>Supported API Levels</th> </tr> </thead> <tbody> <tr> <td>DH</td> <td>1+</td> </tr> <tr> <td>DSA</td> <td>1+</td> </tr> <tr> <td>EC</td> <td>11+</td> </tr> <tr> <td>RSA</td> <td>1+</td> </tr> </tbody> </table>

These algorithms are described in the KeyPairGenerator section of the Java Cryptography Architecture Standard Algorithm Name Documentation.

Added in 1.1.

Java documentation for java.security.KeyPairGenerator.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

KeyPairGenerator(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

KeyPairGenerator(String)

Creates a KeyPairGenerator object for the specified algorithm.

Properties

Algorithm

Returns the standard name of the algorithm for this key pair generator.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
Provider

Returns the provider of this key pair generator object.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GenerateKeyPair()

Generates a key pair.

GenKeyPair()

Generates a key pair.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetInstance(String, Provider)

Returns a KeyPairGenerator object that generates public/private key pairs for the specified algorithm.

GetInstance(String, String)

Returns a KeyPairGenerator object that generates public/private key pairs for the specified algorithm.

GetInstance(String)

Returns a KeyPairGenerator object that generates public/private key pairs for the specified algorithm.

Initialize(IAlgorithmParameterSpec, SecureRandom)

Initializes the key pair generator using the specified parameter set and user-provided source of randomness.

(Inherited from KeyPairGeneratorSpi)
Initialize(IAlgorithmParameterSpec)

Initializes the key pair generator using the specified parameter set and the SecureRandom implementation of the highest-priority installed provider as the source of randomness.

Initialize(Int32, SecureRandom)

Initializes the key pair generator for a certain keysize with the given source of randomness (and a default parameter set).

Initialize(Int32)

Initializes the key pair generator for a certain keysize using a default parameter set and the SecureRandom implementation of the highest-priority installed provider as the source of randomness.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to