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