A new purely algebraic algorithm is presented for computation of invariants (generalized Casimir operators) of Lie algebras. It uses the Cartans method of moving frames and the knowledge of the group of inner automorphisms of each Lie algebra. The algorithm is applied, in particular, to computation of invariants of real low-dimensional Lie algebras. A number of examples are calculated to illustrate its effectiveness and to make a comparison with the same cases in the literature. Bases of invariants of the real solvable Lie algebras up to dimension five, the real six-dimensional nilpotent Lie algebras and the real six-dimensional solvable Lie algebras with four-dimensional nilradicals are newly calculated and listed in tables.