تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مساعدة في انشاء برنامج التشفير
#9
فيه دالتين Encrypt and Decrypt
كود :
Public Function Encrypt(ByVal text As String, ByVal key As String) As String        Try
            Dim crp As New TripleDESCryptoServiceProvider
            Dim uEncode As New UnicodeEncoding
            Dim bytPlainText() As Byte = uEncode.GetBytes(text)
            Dim stmCipherText As New MemoryStream
            Dim slt() As Byte = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
            Dim pdb As New Rfc2898DeriveBytes(key, slt)
            Dim bytDerivedKey() As Byte = pdb.GetBytes(24)


            crp.Key = bytDerivedKey
            crp.IV = pdb.GetBytes(8)


            Dim csEncrypted As New CryptoStream(stmCipherText, crp.CreateEncryptor(), CryptoStreamMode.Write)


            csEncrypted.Write(bytPlainText, 0, bytPlainText.Length)
            csEncrypted.FlushFinalBlock()
            Return Convert.ToBase64String(stmCipherText.ToArray())
        Catch ex As Exception
            Throw
        End Try
    End Function
    Function Decrypt(ByVal text As String, ByVal key As String) As String


        Dim crp As TripleDESCryptoServiceProvider
        Try
            crp = New TripleDESCryptoServiceProvider
            Dim uEncode As New UnicodeEncoding
            Dim bytCipherText() As Byte = Convert.FromBase64String(text)
            Dim stmPlainText As New MemoryStream
            Dim stmCipherText As New MemoryStream(bytCipherText)
            Dim slt() As Byte = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
            Dim pdb As New Rfc2898DeriveBytes(key, slt)
            Dim bytDerivedKey() As Byte = pdb.GetBytes(24)
            crp.Key = bytDerivedKey
            crp.IV = pdb.GetBytes(8)


            Dim csDecrypted As New CryptoStream(stmCipherText, crp.CreateDecryptor(), CryptoStreamMode.Read)
            Dim sw As New StreamWriter(stmPlainText)
            Dim sr As New StreamReader(csDecrypted)
            sw.Write(sr.ReadToEnd)
            sw.Flush()
            csDecrypted.Clear()
            crp.Clear()
            Return uEncode.GetString(stmPlainText.ToArray())
        Catch ex As Exception
            Throw
        End Try


    End Function

لاتنسى
كود :
Imports System.Security.Cryptography
اللهم إني أعوذ بك من غلبة الدين وغلبة العدو، اللهم إني أعوذ بك من جهد البلاء ومن درك الشقاء ومن سوء القضاء ومن شماتة الأعداء
اللهم اغفر لي خطيئتي وجهلي، وإسرافي في أمري وما أنت أعلم به مني، اللهم اغفر لي ما قدمت وما أخرت، وما أسررت وما أعلنت وما أنت أعلم به مني، أنت المقدم وأنت المؤخر وأنت على كل شيء قدير
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
مساعدة في انشاء برنامج التشفير - بواسطة سعود - 06-04-13, 02:19 AM


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


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