Cyber-physical system security, optimal control, and consensus protocols for nonlinear stochastic systems