تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
حول التشفير وفك التشفير
#1
``` namespace WindowsFormsApp3

{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static string method_1(string string_0)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (byte b in Encoding.UTF8.GetBytes(string_0))
            {
                stringBuilder.Append(string.Format("{0:x2}", b));
            }
            return stringBuilder.ToString();
        }

        public static string Encrypt(string plainText)
        {
            string encrypt_key = ("123456789");
            byte[] key = SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(encrypt_key));
            byte[] iv = new byte[16];
            Aes aes = Aes.Create();
            aes.Mode = CipherMode.CBC;
            aes.Key = key;
            aes.IV = iv;
            MemoryStream memoryStream = new MemoryStream();
            ICryptoTransform transform = aes.CreateEncryptor();
            CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);
            byte[] bytes = Encoding.ASCII.GetBytes(plainText);
            cryptoStream.Write(bytes, 0, bytes.Length);
            cryptoStream.FlushFinalBlock();
            byte[] array = memoryStream.ToArray();
            memoryStream.Close();
            cryptoStream.Close();
            return Convert.ToBase64String(array, 0, array.Length);
        }

        public static string Decrypt(string cipherText)
        {
            {
                string decrypt_key = ("123456789");
                byte[] key = SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(decrypt_key));
                byte[] iv = new byte[16];
                Aes aes = Aes.Create();
                aes.Mode = CipherMode.CBC;
                aes.Key = key;
                aes.IV = iv;
                MemoryStream memoryStream = new MemoryStream();
                ICryptoTransform transform = aes.CreateEncryptor();
                CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);
                byte[] bytes = Convert.FromBase64String(cipherText);
                cryptoStream.Write(bytes, 0, bytes.Length);
                cryptoStream.FlushFinalBlock();
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                cryptoStream.Close();
                return Encoding.ASCII.GetString(array, 0, array.Length);

            }

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            textBoxen.Text = Encrypt(textBoxva.Text);
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            textBoxde.Text = Decrypt(textBoxen.Text);
        }
```
بس النتيجة ما تظهر 

ممكن افادة


الرد }}
تم الشكر بواسطة:
#2
جرب هذا الكود :

PHP كود :
       #region EncryptDecryptWord
 
       public string Encrypt(string textstring key)
 
       {
 
           if (Operators.CompareString(text""TextComparefalse) == 0)
 
           {
 
               return text;
 
           }
 
           try
            
{
 
               System.Security.Cryptography.TripleDESCryptoServiceProvider crp = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
 
               UnicodeEncoding uEncode = new UnicodeEncoding();
 
               byte[] bytPlainText uEncode.GetBytes(text);
 
               System.IO.MemoryStream stmCipherText = new System.IO.MemoryStream();
 
               byte[] slt = new byte[] { 0123456789101112 };
 
               System.Security.Cryptography.Rfc2898DeriveBytes pdb = new System.Security.Cryptography.Rfc2898DeriveBytes(keyslt);
 
               byte[] bytDerivedKey pdb.GetBytes(24);
 
               crp.Key bytDerivedKey;
 
               crp.IV pdb.GetBytes(8);
 
               System.Security.Cryptography.CryptoStream csEncrypted = new System.Security.Cryptography.CryptoStream(stmCipherTextcrp.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
 
               csEncrypted.Write(bytPlainText0bytPlainText.Length);
 
               csEncrypted.FlushFinalBlock();
 
               return Convert.ToBase64String(stmCipherText.ToArray());
 
           }
 
           catch (Exception ex)
 
           {
 
               Microsoft.VisualBasic.Interaction.MsgBox(ex.MessageMicrosoft.VisualBasic.MsgBoxStyle.Critical"Error");
 
               return null;
 
           }
 
       }
 
       public string Decrypt(string textstring key)
 
       {
 
           if (Operators.CompareString(text""TextComparefalse) == 0)
 
           {
 
               return text;
 
           }

 
           try
            
{
 
               System.Security.Cryptography.TripleDESCryptoServiceProvider crp = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
 
               UnicodeEncoding uEncode = new UnicodeEncoding();
 
               byte[] bytCipherText Convert.FromBase64String(text);
 
               System.IO.MemoryStream stmPlainText = new System.IO.MemoryStream();
 
               System.IO.MemoryStream stmCipherText = new System.IO.MemoryStream(bytCipherText);
 
               byte[] slt = new byte[] { 0123456789101112 };
 
               System.Security.Cryptography.Rfc2898DeriveBytes pdb = new System.Security.Cryptography.Rfc2898DeriveBytes(keyslt);
 
               byte[] bytDerivedKey pdb.GetBytes(24);
 
               crp.Key bytDerivedKey;
 
               crp.IV pdb.GetBytes(8);
 
               System.Security.Cryptography.CryptoStream csDecrypted = new System.Security.Cryptography.CryptoStream(stmCipherTextcrp.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Read);
 
               System.IO.StreamWriter sw = new System.IO.StreamWriter(stmPlainText);
 
               System.IO.StreamReader sr = new System.IO.StreamReader(csDecrypted);
 
               sw.Write(sr.ReadToEnd());
 
               sw.Flush();
 
               csDecrypted.Clear();
 
               crp.Clear();
 
               return uEncode.GetString(stmPlainText.ToArray());
 
           }
 
           catch (Exception ex)
 
           {
 
               Microsoft.VisualBasic.Interaction.MsgBox(ex.MessageMicrosoft.VisualBasic.MsgBoxStyle.Critical"Error");
 
               return null;
 
           }
 
       }
 
       #endregion 
الرد }}
تم الشكر بواسطة: ابراهيم ايبو


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
Lightbulb [مشروع] سوال على التشفير sirwan 0 906 05-01-20, 08:37 PM
آخر رد: sirwan
  فك التشفير bidaya 5 1,717 08-07-19, 02:04 AM
آخر رد: elgokr
Information [سؤال] مساعده في التشفير beko mamoun 0 1,736 13-04-15, 01:56 AM
آخر رد: beko mamoun

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم