< prev index next >

src/jdk.crypto.ec/share/classes/sun/security/ec/ECPrivateKeyImpl.java

Print this page




  56  * }
  57  * </pre>
  58  *
  59  * We currently ignore the optional parameters and publicKey fields. We
  60  * require that the parameters are encoded as part of the AlgorithmIdentifier,
  61  * not in the private key structure.
  62  *
  63  * @since   1.6
  64  * @author  Andreas Sterbenz
  65  */
  66 public final class ECPrivateKeyImpl extends PKCS8Key implements ECPrivateKey {
  67 
  68     private static final long serialVersionUID = 88695385615075129L;
  69 
  70     private BigInteger s;       // private value
  71     private ECParameterSpec params;
  72 
  73     /**
  74      * Construct a key from its encoding. Called by the ECKeyFactory.
  75      */
  76     ECPrivateKeyImpl(byte[] encoded) throws InvalidKeyException {
  77         decode(encoded);
  78     }
  79 
  80     /**
  81      * Construct a key from its components. Used by the
  82      * KeyFactory.
  83      */
  84     ECPrivateKeyImpl(BigInteger s, ECParameterSpec params)
  85             throws InvalidKeyException {
  86         this.s = s;
  87         this.params = params;
  88         // generate the encoding
  89         algid = new AlgorithmId
  90             (AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params));
  91         try {
  92             DerOutputStream out = new DerOutputStream();
  93             out.putInteger(1); // version 1
  94             byte[] privBytes = ECUtil.trimZeroes(s.toByteArray());
  95             out.putOctetString(privBytes);
  96             DerValue val =
  97                 new DerValue(DerValue.tag_Sequence, out.toByteArray());
  98             key = val.toByteArray();
  99         } catch (IOException exc) {
 100             // should never occur
 101             throw new InvalidKeyException(exc);
 102         }
 103     }
 104 




  56  * }
  57  * </pre>
  58  *
  59  * We currently ignore the optional parameters and publicKey fields. We
  60  * require that the parameters are encoded as part of the AlgorithmIdentifier,
  61  * not in the private key structure.
  62  *
  63  * @since   1.6
  64  * @author  Andreas Sterbenz
  65  */
  66 public final class ECPrivateKeyImpl extends PKCS8Key implements ECPrivateKey {
  67 
  68     private static final long serialVersionUID = 88695385615075129L;
  69 
  70     private BigInteger s;       // private value
  71     private ECParameterSpec params;
  72 
  73     /**
  74      * Construct a key from its encoding. Called by the ECKeyFactory.
  75      */
  76     public ECPrivateKeyImpl(byte[] encoded) throws InvalidKeyException {
  77         decode(encoded);
  78     }
  79 
  80     /**
  81      * Construct a key from its components. Used by the
  82      * KeyFactory.
  83      */
  84     public ECPrivateKeyImpl(BigInteger s, ECParameterSpec params)
  85             throws InvalidKeyException {
  86         this.s = s;
  87         this.params = params;
  88         // generate the encoding
  89         algid = new AlgorithmId
  90             (AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params));
  91         try {
  92             DerOutputStream out = new DerOutputStream();
  93             out.putInteger(1); // version 1
  94             byte[] privBytes = ECUtil.trimZeroes(s.toByteArray());
  95             out.putOctetString(privBytes);
  96             DerValue val =
  97                 new DerValue(DerValue.tag_Sequence, out.toByteArray());
  98             key = val.toByteArray();
  99         } catch (IOException exc) {
 100             // should never occur
 101             throw new InvalidKeyException(exc);
 102         }
 103     }
 104 


< prev index next >