@Override
    protected SecretKey engineGenerateSecret(KeySpec keySpec) throws InvalidKeySpecException {
        if (keySpec == null) {
            throw new InvalidKeySpecException("Null KeySpec");
        }
        if (keySpec instanceof SecretKeySpec) {
            SecretKeySpec key = (SecretKeySpec) keySpec;
            try {
                if (!DESedeKeySpec.isParityAdjusted(key.getEncoded(), 0)) {
                    throw new InvalidKeySpecException(
                            "SecretKeySpec is not a parity-adjusted DESEDE key");
                }
            } catch (InvalidKeyException e) {
                throw new InvalidKeySpecException(e);
            }
            return key;
        } else if (keySpec instanceof DESedeKeySpec) {
            DESedeKeySpec desKeySpec = (DESedeKeySpec) keySpec;
            return new SecretKeySpec(desKeySpec.getKey(), "DESEDE");
        } else {
            throw new InvalidKeySpecException(
                    "Unsupported KeySpec class: " + keySpec.getClass().getName());
        }
    }
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