/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* EC KeyFactory implemenation.
*
* @author Andreas Sterbenz
* @since 1.6
*/
}
}
}
// Check that spec is a known supported curve and convert it to our
// ECParameterSpec subclass. If not possible, return null.
}
}
}
}
// Used by ECDH KeyAgreement
if (key instanceof ECPublicKeyImpl) {
} else if (key instanceof ECPublicKey) {
} else {
// should never occur
throw new InvalidKeyException
}
}
try {
if (key instanceof ECPublicKey) {
return generatePublic(
);
// let Sun provider parse for us, then recurse
return implTranslatePublicKey(key);
} else {
throw new InvalidKeyException("PublicKey must be instance "
+ "of ECPublicKey or have X.509 encoding");
}
} catch (PKCS11Exception e) {
throw new InvalidKeyException("Could not create EC public key", e);
}
}
throws InvalidKeyException {
try {
if (key instanceof ECPrivateKey) {
return generatePrivate(
);
// let Sun provider parse for us, then recurse
return implTranslatePrivateKey(key);
} else {
throw new InvalidKeyException("PrivateKey must be instance "
+ "of ECPrivateKey or have PKCS#8 encoding");
}
} catch (PKCS11Exception e) {
throw new InvalidKeyException("Could not create EC private key", e);
}
}
// see JCA spec
throws InvalidKeySpecException {
token.ensureValid();
if (keySpec instanceof X509EncodedKeySpec) {
try {
return implTranslatePublicKey(key);
} catch (InvalidKeyException e) {
throw new InvalidKeySpecException
("Could not create EC public key", e);
}
}
if (keySpec instanceof ECPublicKeySpec == false) {
throw new InvalidKeySpecException("Only ECPublicKeySpec and "
+ "X509EncodedKeySpec supported for EC public keys");
}
try {
return generatePublic(
);
} catch (PKCS11Exception e) {
throw new InvalidKeySpecException
("Could not create EC public key", e);
}
}
// see JCA spec
throws InvalidKeySpecException {
token.ensureValid();
if (keySpec instanceof PKCS8EncodedKeySpec) {
try {
return implTranslatePrivateKey(key);
} catch (GeneralSecurityException e) {
throw new InvalidKeySpecException
("Could not create EC private key", e);
}
}
if (keySpec instanceof ECPrivateKeySpec == false) {
throw new InvalidKeySpecException("Only ECPrivateKeySpec and "
+ "PKCS8EncodedKeySpec supported for EC private keys");
}
try {
return generatePrivate(
);
} catch (PKCS11Exception e) {
throw new InvalidKeySpecException
("Could not create EC private key", e);
}
}
byte[] encodedPoint =
// Check whether the X9.63 encoding of an EC point shall be wrapped
// in an ASN.1 OCTET STRING
try {
.toByteArray();
} catch (IOException e) {
throw new
IllegalArgumentException("Could not DER encode point", e);
}
}
};
try {
} finally {
}
}
new CK_ATTRIBUTE(CKA_VALUE, s),
};
try {
return P11Key.privateKey
} finally {
}
}
throws PKCS11Exception, InvalidKeySpecException {
new CK_ATTRIBUTE(CKA_EC_POINT),
new CK_ATTRIBUTE(CKA_EC_PARAMS),
};
try {
} catch (IOException e) {
throw new InvalidKeySpecException("Could not parse key", e);
}
} else { // X.509 handled in superclass
throw new InvalidKeySpecException("Only ECPublicKeySpec and "
+ "X509EncodedKeySpec supported for EC public keys");
}
}
throws PKCS11Exception, InvalidKeySpecException {
new CK_ATTRIBUTE(CKA_VALUE),
new CK_ATTRIBUTE(CKA_EC_PARAMS),
};
try {
} catch (IOException e) {
throw new InvalidKeySpecException("Could not parse key", e);
}
} else { // PKCS#8 handled in superclass
throw new InvalidKeySpecException("Only ECPrivateKeySpec "
+ "and PKCS8EncodedKeySpec supported for EC private keys");
}
}
}
}