@Override
    protected KeySpec engineGetKeySpec(SecretKey secretKey,
            @SuppressWarnings("rawtypes") Class aClass) throws InvalidKeySpecException {
        if (secretKey == null) {
            throw new InvalidKeySpecException("Null SecretKey");
        }
        if (aClass == SecretKeySpec.class) {
            try {
                if (!DESedeKeySpec.isParityAdjusted(secretKey.getEncoded(), 0)) {
                    throw new InvalidKeySpecException("SecretKey is not a parity-adjusted DESEDE key");
                }
            } catch (InvalidKeyException e) {
                throw new InvalidKeySpecException(e);
            }
            if (secretKey instanceof SecretKeySpec) {
                return (KeySpec) secretKey;
            } else {
                return new SecretKeySpec(secretKey.getEncoded(), "DESEDE");
            }
        } else if (aClass == DESedeKeySpec.class) {
            try {
                return new DESedeKeySpec(secretKey.getEncoded());
            } catch (InvalidKeyException e) {
                throw new InvalidKeySpecException(e);
            }
        } else {
            throw new InvalidKeySpecException("Unsupported KeySpec class: " + aClass);
        }
    }
An implementation of {@link javax.crypto.SecretKeyFactory} for use with DESEDE keys.  This
class supports {@link SecretKeySpec} and {@link DESedeKeySpec} for key specs.
common/src/main/java/org/conscrypt/DESEDESecretKeyFactory.java