تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] طلب دالة تشفي النصوص
#2
تشفيرة AES هي تشفيرة قوية جدا وحسب معلوماتي لم يتم كسرها حتى الان

تاخذ مفتاحين . الاول Key , والاخر IV

حيث يتم انتاج المفتاحين عند عملية التشفير

وعند عملية فك التشفير تقوم باعطاء الدالة المفتاحين الذان تم انتاجهما

فالبيانات يتم توليدها حسب صحة المفتاحين .. فلو ادخلت حرف واحد خطا من المفتاح ، سيظهر لك نص اخر

المثال مرفق بالسي شارب





كود المثال محول لVB


PHP كود :
Imports System.Collections.Generic
Imports System
.ComponentModel
Imports System
.Data
Imports System
.Drawing
Imports System
.IO
Imports System
.Linq
Imports System
.Security.Cryptography
Imports System
.Text
Imports System
.Threading.Tasks
Imports System
.Windows.Forms

    
Public Partial Class Form1
        Inherits Form
        
Public Sub New()
            
InitializeComponent()
        
End Sub

        
Private Shared Function EncryptStringToBytes(plainText As StringKey As Byte(), IV As Byte()) As Byte()
            
' Check arguments. 
            If plainText Is Nothing OrElse plainText.Length <= 0 Then
                Throw New ArgumentNullException("plainText")
            End If
            If Key Is Nothing OrElse Key.Length <= 0 Then
                Throw New ArgumentNullException("Key")
            End If
            If IV Is Nothing OrElse IV.Length <= 0 Then
                Throw New ArgumentNullException("Key")
            End If
            Dim encrypted As Byte()
            ' 
Create an RijndaelManaged object 
            
' with the specified key and IV. 
            Using rijAlg As New RijndaelManaged()
                rijAlg.Key = Key
                rijAlg.IV = IV

                ' 
Create a decrytor to perform the stream transform.
                
Dim encryptor As ICryptoTransform rijAlg.CreateEncryptor(rijAlg.KeyrijAlg.IV)

                
' Create the streams used for encryption. 
                Using msEncrypt As New MemoryStream()
                    Using csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)
                        Using swEncrypt As New StreamWriter(csEncrypt)

                            '
Write all data to the stream.
                            
swEncrypt.Write(plainText)
                        
End Using
                        encrypted 
msEncrypt.ToArray()
                    
End Using
                End Using
            End Using


            
' Return the encrypted bytes from the memory stream. 
            Return encrypted

        End Function

        Private Shared Function DecryptStringFromBytes(cipherText As Byte(), Key As Byte(), IV As Byte()) As String
            ' 
Check arguments
            If 
cipherText Is Nothing OrElse cipherText.Length <= 0 Then
                
Throw New ArgumentNullException("cipherText")
            
End If
            If 
Key Is Nothing OrElse Key.Length <= 0 Then
                
Throw New ArgumentNullException("Key")
            
End If
            If 
IV Is Nothing OrElse IV.Length <= 0 Then
                
Throw New ArgumentNullException("Key")
            
End If

            
' Declare the string used to hold 
            ' 
the decrypted text
            
Dim plaintext As String Nothing

            
' Create an RijndaelManaged object 
            ' 
with the specified key and IV
            
Using rijAlg As New RijndaelManaged()
                
rijAlg.Key Key
                rijAlg
.IV IV

                
' Create a decrytor to perform the stream transform.
                Dim decryptor As ICryptoTransform = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV)

                ' 
Create the streams used for decryption
                
Using msDecrypt As New MemoryStream(cipherText)
                    
Using csDecrypt As New CryptoStream(msDecryptdecryptorCryptoStreamMode.Read)
                        
Using srDecrypt As New StreamReader(csDecrypt)

                            
' Read the decrypted bytes from the decrypting stream 
                            ' 
and place them in a string.
                            
plaintext srDecrypt.ReadToEnd()
                        
End Using
                    End Using

                End Using
            End Using

            
Return plaintext
        End 
Function

        Private 
Sub button1_Click(sender As ObjectAs EventArgs)
            
Using myRijndael As New RijndaelManaged()

                
myRijndael.GenerateKey()
                
myRijndael.GenerateIV()

                
' Encrypt the string to an array of bytes. 
                textBox2.Text = Convert.ToBase64String(EncryptStringToBytes(textBox1.Text, myRijndael.Key, myRijndael.IV))


                textBox3.Text = Convert.ToBase64String(myRijndael.Key).ToString()
                textBox4.Text = Convert.ToBase64String(myRijndael.IV).ToString()
            End Using
        End Sub

        Private Sub button2_Click(sender As Object, e As EventArgs)
            Try
                Using myRijndael As New RijndaelManaged()
                    Dim chiperText As Byte() = Convert.FromBase64String(textBox5.Text.Trim())
                    myRijndael.Key = Convert.FromBase64String(textBox6.Text.Trim())
                    myRijndael.IV = Convert.FromBase64String(textBox7.Text.Trim())
                    ' 
Decrypt the bytes to a string
                    
Dim orginalText As String DecryptStringFromBytes(chiperTextmyRijndael.KeymyRijndael.IV)

                    
textBox8.Text orginalText
                End Using
            
Catch
                
MessageBox.Show("لايمكن فك التشفيرة""error"MessageBoxButtons.OKMessageBoxIcon.[Error])
            
End Try
        
End Sub

    End 
Class 


الملفات المرفقة
.rar   EncryptDecrypt using AES.rar (الحجم : 55.8 ك ب / التحميلات : 156)
الرد }}}
تم الشكر بواسطة: abulayth , sooriaty03 , hoob computer , mamas1


الردود في هذا الموضوع
طلب دالة تشفي النصوص - بواسطة ali.alfoly - 30-11-13, 08:37 PM
RE: طلب دالة تشفي النصوص - بواسطة الشاكي لله - 30-11-13, 11:26 PM
RE: طلب دالة تشفي النصوص - بواسطة ali.alfoly - 01-12-13, 09:42 AM
RE: طلب دالة تشفي النصوص - بواسطة ali.alfoly - 02-12-13, 11:13 PM
RE: طلب دالة تشفي النصوص - بواسطة mamas1 - 03-12-13, 06:26 PM
RE: طلب دالة تشفي النصوص - بواسطة ali.alfoly - 08-12-13, 01:43 AM


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


يقوم بقرائة الموضوع: