Question : Crypt some text and Decrypt it

Hi ,
i wanna hide my password in a text file.But when users opened the file they will see a text like ; " asdasd8978912!'^!'âskldjahdkj";
when i decrypt it with my program it will be ; "Hi Honey Its me get me in " :)
its like a simple Crypt/Decrypt thing.
Gimme examples thanx.

Answer : Crypt some text and Decrypt it

I have some vb code - I have made this into a class. You will need to add the appropriate libraries to your project:

You then use it like this:

EncryptedValue = Encryption.Encrypt("%ffe^drty*daSFaERt£", "Let me in")


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Security.Cryptography
 
Public Class Encryption
   Private Shared key() As Byte = {}
   Private Shared IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
 
   Public Shared Function Decrypt(ByVal sEncryptionKey As String, ByVal stringToDecrypt As String) As String
      Dim inputByteArray(stringToDecrypt.Length) As Byte
      Try
         key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey, 8))
         Dim des As New DESCryptoServiceProvider
         inputByteArray = Convert.FromBase64String(stringToDecrypt)
         Dim ms As New MemoryStream
         Dim cs As New CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write)
         cs.Write(inputByteArray, 0, inputByteArray.Length)
         cs.FlushFinalBlock()
         Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
         Return encoding.GetString(ms.ToArray())
      Catch e As Exception
         Return e.Message
      End Try
   End Function
 
   Public Shared Function Encrypt(ByVal SEncryptionKey As String, ByVal stringToEncrypt As String) As String
      Try
         key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKey, 8))
         Dim des As New DESCryptoServiceProvider
         Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(stringToEncrypt)
         Dim ms As New MemoryStream
         Dim cs As New CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write)
         cs.Write(inputByteArray, 0, inputByteArray.Length)
         cs.FlushFinalBlock()
         Return Convert.ToBase64String(ms.ToArray())
      Catch e As Exception
         Return e.Message
      End Try
   End Function
 
End Class
Random Solutions  
 
programming4us programming4us