تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[نقاش] سؤال فى مشاركة احد الاعضاء ؟!
#1
لقد كنت ابحث عن طريقة لتشفير النصوص فوجدت مثال رائع للاخ RaggiTech و هو قام مشكورا بصنع ملف dll ليقوم بتشفير النصوص ومن امكانيات هذا الملف انة عندما يتم التشفير على جهاز لا يستطيع جهاز اخر فك التشفير سؤالى هو كيف تكون هذة ميزة و انا شفرت مثلا كلمة مرور او اى شيئ و اود ان اقوم بفك التشفير على جهاز العميل ليستخدم البرنامج كلمة المرور المشفرة اذا كنت مخطئ او فهمت الموضوع بطريقة خاطئة ارجو التوضيح من الاخوة و هذا رابط المشاركة فى قسم المقالات http://vb4arb.com/vb/thread-4723.html
الرد }}}
تم الشكر بواسطة:
#2
ما تقوله معناه ان هناك خطا في اسلوب التشفير
وأرد عليك وأقول أين ستكون الفائدة هنا من التشفير .... فأنت هكذا تقوم بتشفير البيانات لنفسك فقط و مع ذلك كل شئ يمكن ان يتم فك التشفير الخاص به لكنك ليس لديك اصل الكود الذي قام بالتشفير

عموما فيه الف اسلوب و اسلوب للتشفير و عليك فقط ان تبني الدوال الخاصة بك

في النهاية طالما الملفات التي تستخدم في التشفير تعتمد علي الدوت نت او تعتمد علي اساس ثابت إذن فهي يجب ان تكون صالحة للإستخدام علي جميع اجهزة الكمبيوتر


الكود التالي موجود علي النت و يمكن ان تستخدمه و تطور فيه
انا عن نفسي توقفت عن استخدام Cryptography و بأقوم بالتشفير بأساليب اخري
PHP كود :
Imports System.Text
Imports System
.Security.Cryptography
Imports System
.IO

Public Class StringCipher

    Private Sub 
New()
 
   End Sub
    
' This constant is used to determine the keysize of the encryption algorithm in bits.
    ' 
We divide this by 8 within the code below to get the equivalent number of bytes.
 
   Private Const Keysize As Integer 256

    
' This constant determines the number of iterations for the password bytes generation function.
    Private Const DerivationIterations As Integer = 1000

    Public Shared Function Encrypt(plainText As String, passPhrase As String) As String
        ' 
Salt and IV is randomly generated each timebut is preprended to encrypted cipher text
        
' so that the same Salt and IV values can be used when decrypting.  
        Dim saltStringBytes = Generate256BitsOfRandomEntropy()
        Dim ivStringBytes = Generate256BitsOfRandomEntropy()
        Dim plainTextBytes = Encoding.UTF8.GetBytes(plainText)
        Using password = New Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations)
            Dim keyBytes = password.GetBytes(Keysize \ 8)
            Using symmetricKey = New RijndaelManaged()
                symmetricKey.BlockSize = 256
                symmetricKey.Mode = CipherMode.CBC
                symmetricKey.Padding = PaddingMode.PKCS7
                Using encryptor = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes)
                    Using memoryStream = New MemoryStream()
                        Using cryptoStream = New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)
                            cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
                            cryptoStream.FlushFinalBlock()
                            ' 
Create the final bytes as a concatenation of the random salt bytesthe random iv bytes and the cipher bytes.
 
                           Dim cipherTextBytes saltStringBytes
                            cipherTextBytes 
cipherTextBytes.Concat(ivStringBytes).ToArray()
 
                           cipherTextBytes cipherTextBytes.Concat(memoryStream.ToArray()).ToArray()
 
                           memoryStream.Close()
 
                           cryptoStream.Close()
 
                           Return Convert.ToBase64String(cipherTextBytes)
 
                       End Using
                    End Using
                End Using
            End Using
        End Using
    End 
Function

 
   Public Shared Function Decrypt(cipherText As StringpassPhrase As String) As String
        
' Get the complete stream of bytes that represent:
        ' 
[32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText]
 
       Dim cipherTextBytesWithSaltAndIv Convert.FromBase64String(cipherText)
 
       ' Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes.
        Dim saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize \ 8).ToArray()
        ' 
Get the IV bytes by extracting the next 32 bytes from the supplied cipherText bytes.
 
       Dim ivStringBytes cipherTextBytesWithSaltAndIv.Skip(Keysize 8).Take(Keysize 8).ToArray()
 
       ' Get the actual cipher text bytes by removing the first 64 bytes from the cipherText string.
        Dim cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize \ 8) * 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize \ 8) * 2)).ToArray()

        Using password = New Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations)
            Dim keyBytes = password.GetBytes(Keysize \ 8)
            Using symmetricKey = New RijndaelManaged()
                symmetricKey.BlockSize = 256
                symmetricKey.Mode = CipherMode.CBC
                symmetricKey.Padding = PaddingMode.PKCS7
                Using decryptor = symmetricKey.CreateDecryptor(keyBytes, ivStringBytes)
                    Using memoryStream = New MemoryStream(cipherTextBytes)
                        Using cryptoStream = New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)
                            Dim plainTextBytes = New Byte(cipherTextBytes.Length - 1) {}
                            Dim decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)
                            memoryStream.Close()
                            cryptoStream.Close()
                            Return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount)
                        End Using
                    End Using
                End Using
            End Using
        End Using
    End Function

    Public Shared Function CalculateKey(value As String) As String
        Dim result As String = CType(Nothing, String)
        Using ms As MemoryStream = New MemoryStream()
            Using hash As HashAlgorithm = New SHA256CryptoServiceProvider()
                result = Convert.ToBase64String(hash.ComputeHash(ms)).ToUpper
            End Using
        End Using
        Return result
    End Function

    Private Shared Function Generate256BitsOfRandomEntropy() As Byte()
        Dim randomBytes = New Byte(31) {}
        ' 
32 Bytes will give us 256 bits.
 
       Using rngCsp = New RNGCryptoServiceProvider()
 
           ' Fill the array with cryptographically secure random bytes.
            rngCsp.GetBytes(randomBytes)
        End Using
        Return randomBytes
    End Function

End Class 
الرد }}}
تم الشكر بواسطة:
#3
(25-01-16, 01:12 PM)silverlight كتب : ما تقوله معناه ان هناك خطا في اسلوب التشفير
وأرد عليك وأقول أين ستكون الفائدة هنا من التشفير .... فأنت هكذا تقوم بتشفير البيانات لنفسك فقط و مع ذلك كل شئ يمكن ان يتم فك التشفير الخاص به لكنك ليس لديك اصل الكود الذي قام بالتشفير

عموما فيه الف اسلوب و اسلوب للتشفير و عليك فقط ان تبني الدوال الخاصة بك

في النهاية طالما الملفات التي تستخدم في التشفير تعتمد علي الدوت نت او تعتمد علي اساس ثابت إذن فهي يجب ان تكون صالحة للإستخدام علي جميع اجهزة الكمبيوتر


الكود التالي موجود علي النت و يمكن ان تستخدمه و تطور فيه
انا عن نفسي توقفت عن استخدام Cryptography و بأقوم بالتشفير بأساليب اخري
PHP كود :
Imports System.Text
Imports System
.Security.Cryptography
Imports System
.IO

Public Class StringCipher

    Private Sub 
New()
 
   End Sub
    
' This constant is used to determine the keysize of the encryption algorithm in bits.
    ' 
We divide this by 8 within the code below to get the equivalent number of bytes.
 
   Private Const Keysize As Integer 256

    
' This constant determines the number of iterations for the password bytes generation function.
    Private Const DerivationIterations As Integer = 1000

    Public Shared Function Encrypt(plainText As String, passPhrase As String) As String
        ' 
Salt and IV is randomly generated each timebut is preprended to encrypted cipher text
        
' so that the same Salt and IV values can be used when decrypting.  
        Dim saltStringBytes = Generate256BitsOfRandomEntropy()
        Dim ivStringBytes = Generate256BitsOfRandomEntropy()
        Dim plainTextBytes = Encoding.UTF8.GetBytes(plainText)
        Using password = New Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations)
            Dim keyBytes = password.GetBytes(Keysize \ 8)
            Using symmetricKey = New RijndaelManaged()
                symmetricKey.BlockSize = 256
                symmetricKey.Mode = CipherMode.CBC
                symmetricKey.Padding = PaddingMode.PKCS7
                Using encryptor = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes)
                    Using memoryStream = New MemoryStream()
                        Using cryptoStream = New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)
                            cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
                            cryptoStream.FlushFinalBlock()
                            ' 
Create the final bytes as a concatenation of the random salt bytesthe random iv bytes and the cipher bytes.
 
                           Dim cipherTextBytes saltStringBytes
                            cipherTextBytes 
cipherTextBytes.Concat(ivStringBytes).ToArray()
 
                           cipherTextBytes cipherTextBytes.Concat(memoryStream.ToArray()).ToArray()
 
                           memoryStream.Close()
 
                           cryptoStream.Close()
 
                           Return Convert.ToBase64String(cipherTextBytes)
 
                       End Using
                    End Using
                End Using
            End Using
        End Using
    End 
Function

 
   Public Shared Function Decrypt(cipherText As StringpassPhrase As String) As String
        
' Get the complete stream of bytes that represent:
        ' 
[32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText]
 
       Dim cipherTextBytesWithSaltAndIv Convert.FromBase64String(cipherText)
 
       ' Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes.
        Dim saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize \ 8).ToArray()
        ' 
Get the IV bytes by extracting the next 32 bytes from the supplied cipherText bytes.
 
       Dim ivStringBytes cipherTextBytesWithSaltAndIv.Skip(Keysize 8).Take(Keysize 8).ToArray()
 
       ' Get the actual cipher text bytes by removing the first 64 bytes from the cipherText string.
        Dim cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize \ 8) * 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize \ 8) * 2)).ToArray()

        Using password = New Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations)
            Dim keyBytes = password.GetBytes(Keysize \ 8)
            Using symmetricKey = New RijndaelManaged()
                symmetricKey.BlockSize = 256
                symmetricKey.Mode = CipherMode.CBC
                symmetricKey.Padding = PaddingMode.PKCS7
                Using decryptor = symmetricKey.CreateDecryptor(keyBytes, ivStringBytes)
                    Using memoryStream = New MemoryStream(cipherTextBytes)
                        Using cryptoStream = New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)
                            Dim plainTextBytes = New Byte(cipherTextBytes.Length - 1) {}
                            Dim decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)
                            memoryStream.Close()
                            cryptoStream.Close()
                            Return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount)
                        End Using
                    End Using
                End Using
            End Using
        End Using
    End Function

    Public Shared Function CalculateKey(value As String) As String
        Dim result As String = CType(Nothing, String)
        Using ms As MemoryStream = New MemoryStream()
            Using hash As HashAlgorithm = New SHA256CryptoServiceProvider()
                result = Convert.ToBase64String(hash.ComputeHash(ms)).ToUpper
            End Using
        End Using
        Return result
    End Function

    Private Shared Function Generate256BitsOfRandomEntropy() As Byte()
        Dim randomBytes = New Byte(31) {}
        ' 
32 Bytes will give us 256 bits.
 
       Using rngCsp = New RNGCryptoServiceProvider()
 
           ' Fill the array with cryptographically secure random bytes.
            rngCsp.GetBytes(randomBytes)
        End Using
        Return randomBytes
    End Function

End Class 

شكرا لردك اخى ارجو افادتى بالطرق التى تشفر بها وشكرا
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  مساعدة في حل سؤال بخصةص عرض الوقت عبدالكريم برشدان 2 100 12-04-24, 03:05 PM
آخر رد: عبدالكريم برشدان
  ممكن حل المشكلة فى الكود التالي - من مشاركة استاذنا القدير / عبدالله الدوسري new_programer 4 178 02-03-24, 07:36 PM
آخر رد: new_programer
  سؤال عن عملية حذف سجل من قاعدة البيانات assuhimi 3 264 11-02-24, 08:43 PM
آخر رد: assuhimi
Big Grin [سؤال] سؤال على السريع أبو خالد الشكري 0 188 29-01-24, 08:58 AM
آخر رد: أبو خالد الشكري
  سؤال بسيط يا احبتى فى الله خالد كامل1 4 318 07-01-24, 12:55 AM
آخر رد: Mujahef
  سؤال فى برمجة جهاز الباركود خالد كامل1 6 483 05-01-24, 12:25 AM
آخر رد: HALIM ELEULMA
  سؤال فى عمل تقرير مفصل خالد كامل1 1 283 26-12-23, 04:30 PM
آخر رد: تركي الحلواني
  [سؤال] سؤال محمد العموري 5 376 11-12-23, 10:11 AM
آخر رد: تركي الحلواني
  سؤال في تحريك التحديد في datagrideview maher_haddaf 3 439 23-10-23, 08:27 AM
آخر رد: أبو خالد الشكري
  سؤال حول تصميم التقرير maher_haddaf 4 404 22-10-23, 07:53 PM
آخر رد: maher_haddaf

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


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