throws InvalidKeySpecException {
if (keySpec instanceof PKCS8EncodedKeySpec) {
try {
PrivateKeyInfo.Template pkiTemp = new PrivateKeyInfo.Template();
byte[] data = ((PKCS8EncodedKeySpec) keySpec).getEncoded();
PrivateKeyInfo pki = (PrivateKeyInfo) pkiTemp
.decode(new ByteArrayInputStream(data));
AlgorithmIdentifier algid = pki.getPrivateKeyAlgorithm();
if (!algid.getOID().toString().equals("{1 2 840 10045 2 1}")) // ecPublicKey
throw new IllegalArgumentException("Unsupported key");
ECParameterSpec params = EcCore.getParams(decodeOID(algid
.getParameters()));
SEQUENCE.Template foo = new SEQUENCE.Template();
foo.addElement(new INTEGER.Template());
foo.addElement(new OCTET_STRING.Template());
SEQUENCE ecPrivateKey = (SEQUENCE) foo.decode(new ByteArrayInputStream(
pki.getEncoded()));
OCTET_STRING arrhh = (OCTET_STRING) ecPrivateKey.elementAt(1);
return new EcPrivateKeyImpl(new BigInteger(1, arrhh.toByteArray()),
params);
} catch (Exception e) {
throw new InvalidKeySpecException("Invalid key encoding", e);