author | xuelei |
Wed, 28 Sep 2011 15:10:02 -0700 | |
changeset 10709 | d865c9f21240 |
parent 5506 | 202f599c92aa |
child 13661 | 7c894680910a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
10709
d865c9f21240
7092375: Security Libraries don't build with javac -Werror
xuelei
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.ec; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
||
30 |
import java.security.*; |
|
31 |
import java.security.interfaces.*; |
|
32 |
import java.security.spec.*; |
|
33 |
||
34 |
import sun.security.util.*; |
|
35 |
import sun.security.x509.*; |
|
36 |
||
37 |
/** |
|
38 |
* Key implementation for EC public keys. |
|
39 |
* |
|
40 |
* @since 1.6 |
|
41 |
* @author Andreas Sterbenz |
|
42 |
*/ |
|
43 |
public final class ECPublicKeyImpl extends X509Key implements ECPublicKey { |
|
44 |
||
45 |
private static final long serialVersionUID = -2462037275160462289L; |
|
46 |
||
47 |
private ECPoint w; |
|
48 |
private ECParameterSpec params; |
|
49 |
||
50 |
/** |
|
51 |
* Construct a key from its components. Used by the |
|
52 |
* ECKeyFactory and SunPKCS11. |
|
53 |
*/ |
|
10709
d865c9f21240
7092375: Security Libraries don't build with javac -Werror
xuelei
parents:
5506
diff
changeset
|
54 |
@SuppressWarnings("deprecation") |
2 | 55 |
public ECPublicKeyImpl(ECPoint w, ECParameterSpec params) |
56 |
throws InvalidKeyException { |
|
57 |
this.w = w; |
|
58 |
this.params = params; |
|
59 |
// generate the encoding |
|
60 |
algid = new AlgorithmId |
|
61 |
(AlgorithmId.EC_oid, ECParameters.getAlgorithmParameters(params)); |
|
62 |
key = ECParameters.encodePoint(w, params.getCurve()); |
|
63 |
} |
|
64 |
||
65 |
/** |
|
66 |
* Construct a key from its encoding. Used by RSAKeyFactory. |
|
67 |
*/ |
|
68 |
public ECPublicKeyImpl(byte[] encoded) throws InvalidKeyException { |
|
69 |
decode(encoded); |
|
70 |
} |
|
71 |
||
72 |
// see JCA doc |
|
73 |
public String getAlgorithm() { |
|
74 |
return "EC"; |
|
75 |
} |
|
76 |
||
77 |
// see JCA doc |
|
78 |
public ECPoint getW() { |
|
79 |
return w; |
|
80 |
} |
|
81 |
||
82 |
// see JCA doc |
|
83 |
public ECParameterSpec getParams() { |
|
84 |
return params; |
|
85 |
} |
|
86 |
||
87 |
// Internal API to get the encoded point. Currently used by SunPKCS11. |
|
88 |
// This may change/go away depending on what we do with the public API. |
|
10709
d865c9f21240
7092375: Security Libraries don't build with javac -Werror
xuelei
parents:
5506
diff
changeset
|
89 |
@SuppressWarnings("deprecation") |
2 | 90 |
public byte[] getEncodedPublicValue() { |
91 |
return key.clone(); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Parse the key. Called by X509Key. |
|
96 |
*/ |
|
10709
d865c9f21240
7092375: Security Libraries don't build with javac -Werror
xuelei
parents:
5506
diff
changeset
|
97 |
@SuppressWarnings("deprecation") |
2 | 98 |
protected void parseKeyBits() throws InvalidKeyException { |
99 |
try { |
|
100 |
AlgorithmParameters algParams = this.algid.getParameters(); |
|
101 |
params = algParams.getParameterSpec(ECParameterSpec.class); |
|
102 |
w = ECParameters.decodePoint(key, params.getCurve()); |
|
103 |
} catch (IOException e) { |
|
104 |
throw new InvalidKeyException("Invalid EC key", e); |
|
105 |
} catch (InvalidParameterSpecException e) { |
|
106 |
throw new InvalidKeyException("Invalid EC key", e); |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
// return a string representation of this key for debugging |
|
111 |
public String toString() { |
|
112 |
return "Sun EC public key, " + params.getCurve().getField().getFieldSize() |
|
113 |
+ " bits\n public x coord: " + w.getAffineX() |
|
114 |
+ "\n public y coord: " + w.getAffineY() |
|
115 |
+ "\n parameters: " + params; |
|
116 |
} |
|
117 |
||
118 |
protected Object writeReplace() throws java.io.ObjectStreamException { |
|
119 |
return new KeyRep(KeyRep.Type.PUBLIC, |
|
120 |
getAlgorithm(), |
|
121 |
getFormat(), |
|
122 |
getEncoded()); |
|
123 |
} |
|
124 |
} |