public Key getJceKey(ASN1ObjectIdentifier algorithm, GenericKey key) {
    if (key.getRepresentation() instanceof Key) {
      return (Key) key.getRepresentation();
    }

    if (key.getRepresentation() instanceof byte[]) {
      return new SecretKeySpec((byte[]) key.getRepresentation(), getBaseCipherName(algorithm));
    }

    throw new IllegalArgumentException("unknown generic key type");
  }
  Key getJceKey(GenericKey key) {
    if (key.getRepresentation() instanceof Key) {
      return (Key) key.getRepresentation();
    }

    if (key.getRepresentation() instanceof byte[]) {
      return new SecretKeySpec((byte[]) key.getRepresentation(), "ENC");
    }

    throw new IllegalArgumentException("unknown generic key type");
  }