Lines Matching refs:key

87      * ECPublicKey or ECPrivateKey. Check the key and convert it
88 * to a Sun key if necessary. If the key is not an EC key
97 public static ECKey toECKey(Key key) throws InvalidKeyException {
98 if (key instanceof ECKey) {
99 ECKey ecKey = (ECKey)key;
103 return (ECKey)INSTANCE.translateKey(key);
108 * Check that the given EC key is valid.
110 private static void checkKey(ECKey key) throws InvalidKeyException {
112 if (key instanceof ECPublicKey) {
113 if (key instanceof ECPublicKeyImpl) {
116 } else if (key instanceof ECPrivateKey) {
117 if (key instanceof ECPrivateKeyImpl) {
121 throw new InvalidKeyException("Neither a public nor a private key");
124 String keyAlg = ((Key)key).getAlgorithm();
126 throw new InvalidKeyException("Not an EC key: " + keyAlg);
128 // XXX further sanity checks about whether this key uses supported
133 * Translate an EC key into a Sun EC key. If conversion is
137 protected Key engineTranslateKey(Key key) throws InvalidKeyException {
138 if (key == null) {
141 String keyAlg = key.getAlgorithm();
143 throw new InvalidKeyException("Not an EC key: " + keyAlg);
145 if (key instanceof PublicKey) {
146 return implTranslatePublicKey((PublicKey)key);
147 } else if (key instanceof PrivateKey) {
148 return implTranslatePrivateKey((PrivateKey)key);
150 throw new InvalidKeyException("Neither a public nor a private key");
179 private PublicKey implTranslatePublicKey(PublicKey key)
181 if (key instanceof ECPublicKey) {
182 if (key instanceof ECPublicKeyImpl) {
183 return key;
185 ECPublicKey ecKey = (ECPublicKey)key;
190 } else if ("X.509".equals(key.getFormat())) {
191 byte[] encoded = key.getEncoded();
200 private PrivateKey implTranslatePrivateKey(PrivateKey key)
202 if (key instanceof ECPrivateKey) {
203 if (key instanceof ECPrivateKeyImpl) {
204 return key;
206 ECPrivateKey ecKey = (ECPrivateKey)key;
211 } else if ("PKCS#8".equals(key.getFormat())) {
212 return new ECPrivateKeyImpl(key.getEncoded());
252 protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec)
255 // convert key to one of our keys
256 // this also verifies that the key is a valid EC key and ensures
258 key = engineTranslateKey(key);
262 if (key instanceof ECPublicKey) {
263 ECPublicKey ecKey = (ECPublicKey)key;
270 return (T) new X509EncodedKeySpec(key.getEncoded());
276 } else if (key instanceof ECPrivateKey) {
278 return (T) new PKCS8EncodedKeySpec(key.getEncoded());
280 ECPrivateKey ecKey = (ECPrivateKey)key;
292 throw new InvalidKeySpecException("Neither public nor private key");