1. /*
  2. * @(#)EncodedKeySpec.java 1.20 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.spec;
  8. /**
  9. * This class represents a public or private key in encoded format.
  10. *
  11. * @author Jan Luehe
  12. *
  13. * @version 1.20, 12/19/03
  14. *
  15. * @see java.security.Key
  16. * @see java.security.KeyFactory
  17. * @see KeySpec
  18. * @see X509EncodedKeySpec
  19. * @see PKCS8EncodedKeySpec
  20. *
  21. * @since 1.2
  22. */
  23. public abstract class EncodedKeySpec implements KeySpec {
  24. private byte[] encodedKey;
  25. /**
  26. * Creates a new EncodedKeySpec with the given encoded key.
  27. *
  28. * @param encodedKey the encoded key. The contents of the
  29. * array are copied to protect against subsequent modification.
  30. */
  31. public EncodedKeySpec(byte[] encodedKey) {
  32. this.encodedKey = (byte[])encodedKey.clone();
  33. }
  34. /**
  35. * Returns the encoded key.
  36. *
  37. * @return the encoded key. Returns a new array each time
  38. * this method is called.
  39. */
  40. public byte[] getEncoded() {
  41. return (byte[])this.encodedKey.clone();
  42. }
  43. /**
  44. * Returns the name of the encoding format associated with this
  45. * key specification.
  46. *
  47. * <p>If the opaque representation of a key
  48. * (see {@link java.security.Key Key}) can be transformed
  49. * (see {@link java.security.KeyFactory KeyFactory})
  50. * into this key specification (or a subclass of it),
  51. * <code>getFormat</code> called
  52. * on the opaque key returns the same value as the
  53. * <code>getFormat</code> method
  54. * of this key specification.
  55. *
  56. * @return a string representation of the encoding format.
  57. */
  58. public abstract String getFormat();
  59. }