Algebraic formulation of higher gauge theory