تقييم الموضوع :
  • 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 

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


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  سؤال عن الاسمبلي و النيم سبيس justforit 0 102 07-12-25, 12:28 AM
آخر رد: justforit
  فائدة بخصوص التعامل مع علامات التنصيص مع {سؤال} justforit 4 270 02-11-25, 11:19 PM
آخر رد: justforit
  [نقاش] سؤال MetoDas 2 1,489 20-04-25, 10:21 PM
آخر رد: Kamil
  [سؤال] سؤال ترددت قبل نشرة:طابعة الباركود لماذا تطبع أكثر من ليبل فارغ قبل السليم dr.programming 1 511 20-04-25, 09:26 PM
آخر رد: Kamil
  سؤال لو سمحتم احبتى فى الله خالد كامل1 4 807 09-02-25, 12:02 AM
آخر رد: princelovelorn
  سؤال واستفسار خالد كامل1 1 402 04-02-25, 09:31 PM
آخر رد: aliday03
  سؤال فى تقرير كريستال خالد كامل1 0 393 04-02-25, 05:50 AM
آخر رد: خالد كامل1
Question [VB.NET] هناك سؤال يهم كل مبرمج الماذا برنامجك يظهر على بعض الشاشات اكثر دقه بشكل مصغر ومشوه Microformt 0 448 01-02-25, 03:48 PM
آخر رد: Microformt
  [سؤال] سؤال في الكونسول justforit 1 367 21-12-24, 02:57 PM
آخر رد: aljzazy
  سؤال عن طريقة التعامل مع الفاصلة العشرية المتألق9 2 520 28-09-24, 04:45 PM
آخر رد: المتألق9

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


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