It is legal.
In California and few other states that have embraced the eBike classification (Class I, II, III), riding a bike that has 28mph top speed is perfectly legal. You may not ride it on certain mountain trails.
If you are respectful of the fellow trail users and not drawing too much attention, it should not be a problem. What instigates the authorities and other MTB riders is loud noise and high-speed dirt bike-like riding.