Source for gnu.java.security.key.IKeyPairCodec

   1: /* IKeyPairCodec.java --
   2:    Copyright 2001, 2002, 2006 Free Software Foundation, Inc.
   3: 
   4: This file is a part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2 of the License, or (at
   9: your option) any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; if not, write to the Free Software
  18: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
  19: USA
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version.  */
  37: 
  38: 
  39: package gnu.java.security.key;
  40: 
  41: import gnu.java.security.Registry;
  42: 
  43: import java.security.PrivateKey;
  44: import java.security.PublicKey;
  45: 
  46: /**
  47:  * The visible methods of an object that knows how to encode and decode
  48:  * cryptographic asymmetric keypairs. Codecs are useful for (a) externalising
  49:  * public and private keys for storage and on-the-wire transmission, as well as
  50:  * (b) re-creating their internal Java representation from external sources.
  51:  */
  52: public interface IKeyPairCodec
  53: {
  54:   /** Constant identifying the <i>Raw</i> encoding format. */
  55:   int RAW_FORMAT = Registry.RAW_ENCODING_ID;
  56: 
  57:   /** Constant identifying the <i>X.509</i> encoding format. */
  58:   int X509_FORMAT = Registry.X509_ENCODING_ID;
  59: 
  60:   /** Constant identifying the <i>PKCS#8</i> encoding format. */
  61:   int PKCS8_FORMAT = Registry.PKCS8_ENCODING_ID;
  62: 
  63:   /**
  64:    * Constant identifying the <i>ASN.1</i> encoding format: a combined encoding
  65:    * of <i>X.509</i> for public keys, and <i>PKCS#8</i> for private ones.
  66:    */
  67:   int ASN1_FORMAT = Registry.ASN1_ENCODING_ID;
  68: 
  69:   /**
  70:    * Returns the unique identifier (within this library) of the format used to
  71:    * externalise public and private keys.
  72:    *
  73:    * @return the identifier of the format, the object supports.
  74:    */
  75:   int getFormatID();
  76: 
  77:   /**
  78:    * Encodes an instance of a public key for storage or transmission purposes.
  79:    *
  80:    * @param key the non-null key to encode.
  81:    * @return a byte sequence representing the encoding of the designated key
  82:    *         according to the format supported by this codec.
  83:    * @exception IllegalArgumentException if the designated key is not supported
  84:    *              by this codec.
  85:    */
  86:   byte[] encodePublicKey(PublicKey key);
  87: 
  88:   /**
  89:    * Encodes an instance of a private key for storage or transmission purposes.
  90:    *
  91:    * @param key the non-null key to encode.
  92:    * @return a byte sequence representing the encoding of the designated key
  93:    *         according to the format supported by this codec.
  94:    * @exception IllegalArgumentException if the designated key is not supported
  95:    *              by this codec.
  96:    */
  97:   byte[] encodePrivateKey(PrivateKey key);
  98: 
  99:   /**
 100:    * Decodes an instance of an external public key into its native Java
 101:    * representation.
 102:    *
 103:    * @param input the source of the externalised key to decode.
 104:    * @return a concrete instance of a public key, reconstructed from the
 105:    *         designated input.
 106:    * @exception IllegalArgumentException if the designated input does not
 107:    *              contain a known representation of a public key for the format
 108:    *              supported by the concrete codec.
 109:    */
 110:   PublicKey decodePublicKey(byte[] input);
 111: 
 112:   /**
 113:    * Decodes an instance of an external private key into its native Java
 114:    * representation.
 115:    *
 116:    * @param input the source of the externalised key to decode.
 117:    * @return a concrete instance of a private key, reconstructed from the
 118:    *         designated input.
 119:    * @exception IllegalArgumentException if the designated input does not
 120:    *              contain a known representation of a private key for the format
 121:    *              supported by the concrete codec.
 122:    */
 123:   PrivateKey decodePrivateKey(byte[] input);
 124: }