As the scale of cloud computing expands gradually, the security of data sharing in cloud computing environment is facing more and more challenges. In this study, an improved, efficient data encryption method was proposed, which was based on ciphertext policy attribute-based encryption and controlled time cost using fixed-length ciphertext. The generation and aggregation of public and private keys and the encryption and decryption of data were introduced. Then simulation experiments were carried out in the cloud computing environment. Compared with the traditional ciphertext-policy attribute-based encryption (CP-ABE) algorithm, the improved algorithm had better performance in dealing with massive data and multi-user attributes although the steps increased. The comparison with other improved algorithms suggested that the improved algorithm put forward in this study had a high reliability, which indicated a good practicability of the improved algorithm in safe data sharing under cloud computing environment.