There are increased security challenges that target cloud systems. One of the most important requirements of users in cloud storage is protecting their cloud from attacks and keeping data secure. Modern technologies of machine learning are providing the ability to analyze and classify data perfectly. This paper proposes a model placed between users and the cloud, which is based on two phases. The first of which is protecting the cloud from different types of network attacks and detecting normal and abnormal flow. The second one is categorizing the users' data and then encrypting it based on its importance using different encryption algorithms. The accuracy results of random forest (RF) and decision tree (DT) are 100% of attack detection for each one. For the second phase of classifying data, the algorithms used are the logistic regression (LR) and stochastic gradient descent (SGD) learning which resulted in 98% accuracy for both. Besides, the encryption algorithms that have been adopted are rivest cipher (RC4), triple data encryption (3DES), and advanced encryption standard (AES) for encryption of the classified data according to the importance which will be then stored in the cloud in its secure form.