In this paper, we focus on securing the confidential information of massive multiple-input multiple-output (MIMO) non-orthogonal multiple access (NOMA) networks by exploiting artificial noise (AN). An uplink training scheme is first proposed with minimum mean squared error estimation at the base station. Based on the estimated channel state information, the base station precodes the confidential information and injects the AN. Following this, the ergodic secrecy rate is derived for downlink transmission. An asymptotic secrecy performance analysis is also carried out for a large number of transmit antennas and high transmit power at the base station, respectively, to highlight the effects of key parameters on the secrecy performance of the considered system. Based on the derived ergodic secrecy rate, we propose the joint power allocation of the uplink training phase and downlink transmission phase to maximize the sum secrecy rates of the system. Besides, from the perspective of security, another optimization algorithm is proposed to maximize the energy efficiency. The results show that the combination of massive MIMO technique and AN greatly benefits NOMA networks in term of the secrecy performance. In addition, the effects of the uplink training phase and clustering process on the secrecy performance are revealed. Besides, the proposed optimization algorithms are compared with other baseline algorithms through simulations, and their superiority is validated. Finally, it is shown that the proposed system outperforms the conventional massive MIMO orthogonal multiple access in terms of the secrecy performance.