Krein space quantization in curved and flat spacetimes