1. /*
  2. * @(#)KeyPairGeneratorSpi.java 1.13 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security;
  8. import java.security.spec.AlgorithmParameterSpec;
  9. /**
  10. * <p> This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
  11. * for the <code>KeyPairGenerator</code> class, which is used to generate
  12. * pairs of public and private keys.
  13. *
  14. * <p> All the abstract methods in this class must be implemented by each
  15. * cryptographic service provider who wishes to supply the implementation
  16. * of a key pair generator for a particular algorithm.
  17. *
  18. * <p> In case the client does not explicitly initialize the KeyPairGenerator
  19. * (via a call to an <code>initialize</code> method), each provider must
  20. * supply (and document) a default initialization.
  21. * For example, the <i>Sun</i> provider uses a default modulus size (keysize)
  22. * of 1024 bits.
  23. *
  24. * @author Benjamin Renaud
  25. *
  26. * @version 1.13, 01/23/03
  27. *
  28. * @see KeyPairGenerator
  29. * @see java.security.spec.AlgorithmParameterSpec
  30. */
  31. public abstract class KeyPairGeneratorSpi {
  32. /**
  33. * Initializes the key pair generator for a certain keysize, using
  34. * the default parameter set.
  35. *
  36. * @param keysize the keysize. This is an
  37. * algorithm-specific metric, such as modulus length, specified in
  38. * number of bits.
  39. *
  40. * @param random the source of randomness for this generator.
  41. *
  42. * @exception InvalidParameterException if the <code>keysize</code> is not
  43. * supported by this KeyPairGeneratorSpi object.
  44. */
  45. public abstract void initialize(int keysize, SecureRandom random);
  46. /**
  47. * Initializes the key pair generator using the specified parameter
  48. * set and user-provided source of randomness.
  49. *
  50. * <p>This concrete method has been added to this previously-defined
  51. * abstract class. (For backwards compatibility, it cannot be abstract.)
  52. * It may be overridden by a provider to initialize the key pair
  53. * generator. Such an override
  54. * is expected to throw an InvalidAlgorithmParameterException if
  55. * a parameter is inappropriate for this key pair generator.
  56. * If this method is not overridden, it always throws an
  57. * UnsupportedOperationException.
  58. *
  59. * @param params the parameter set used to generate the keys.
  60. *
  61. * @param random the source of randomness for this generator.
  62. *
  63. * @exception InvalidAlgorithmParameterException if the given parameters
  64. * are inappropriate for this key pair generator.
  65. *
  66. * @since 1.2
  67. */
  68. public void initialize(AlgorithmParameterSpec params,
  69. SecureRandom random)
  70. throws InvalidAlgorithmParameterException {
  71. throw new UnsupportedOperationException();
  72. }
  73. /**
  74. * Generates a key pair. Unless an initialization method is called
  75. * using a KeyPairGenerator interface, algorithm-specific defaults
  76. * will be used. This will generate a new key pair every time it
  77. * is called.
  78. *
  79. * @return the newly generated <tt>KeyPair</tt>
  80. */
  81. public abstract KeyPair generateKeyPair();
  82. }