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


كود :
Imports System
Imports System.IO
Imports System.Security.Cryptography
Class FileEncrypt
Public Shared Function ConvertStringToByteArray(s As [String]) As [Byte]()
Dim ca As [Char]() = s.ToCharArray()
Dim ba(ca.Length - 1) As [Byte]
Dim i As Integer
For i = 0 To ba.Length - 1
ba(i) = Convert.ToByte(ca(i))
Next i
Return ba
End Function 'ConvertStringToByteArray
Public Shared Sub Main()
Dim fs As New FileStream("EncryptedFile.txt", FileMode.Create, FileAccess.Write)
' Creating a file stream
Console.WriteLine("Enter Some Text to be stored in encrypted file:")
Dim strinput As [String] = Console.ReadLine()
Dim bytearrayinput As [Byte]() = ConvertStringToByteArray(strinput)
' DES instance with random key
Dim des As New DESCryptoServiceProvider()
' Create DES Encryptor from this instance
Dim desencrypt As ICryptoTransform = des.CreateEncryptor()
' Create Crypto Stream that transforms file stream using des encryption
Dim cryptostream As New CryptoStream(fs, desencrypt, CryptoStreamMode.Write)
' Write out DES encrypted file
cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
cryptostream.Close()
' Create file stream to read encrypted file back
Dim fsread As New FileStream("EncryptedFile.txt", FileMode.Open, FileAccess.Read)
' Create DES Decryptor from our des instance
Dim desdecrypt As ICryptoTransform = des.CreateDecryptor()
' Create crypto stream set to read and do a des decryption transform on
' incoming bytes
Dim cryptostreamDecr As New CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read)
' Print out the contents of the decrypted file
Console.WriteLine(New StreamReader(cryptostreamDecr).ReadToEnd())
Console.WriteLine ()
Console.WriteLine ("Press Enter to continue...")
Console.ReadLine()
End Sub 'Main
End Class 'FileEncrypt
}}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  تشفير النصوص بطريقة رائعة RaggiTech 0 491 17-10-12, 08:42 PM
آخر رد: RaggiTech
  عمل تشفير وفك تشفير للنصوص RaggiTech 0 367 17-10-12, 05:13 PM
آخر رد: RaggiTech
  عمل Download لملف باستخدام ftp RaggiTech 0 224 17-10-12, 05:11 PM
آخر رد: RaggiTech
  تشفير و فك تشفير DataSet RaggiTech 0 426 17-10-12, 05:06 PM
آخر رد: RaggiTech

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


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