Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
encryption function
#1
Code:
Public Function encrypt(ByVal message As String) As String
  Dim returnMessage As String
  Dim Key As String = "PHDPqfwE3z25f2UYjwwfwg4XSqxvl8WYmy+2h8t6AUg="
  Dim IV As String = "pd5mgMMfDI2Gxm/SKl5I8A=="
  Dim Mode As CipherMode = CipherMode.CBC
  Dim Padding As PaddingMode = PaddingMode.PKCS7
  Dim cipherbytes() As Byte
  Dim sa As SymmetricAlgorithm = Rijndael.Create()
  sa.Key = Convert.FromBase64String(Key)
  sa.IV = Convert.FromBase64String(IV)
  sa.Mode = Mode
  sa.Padding = Padding
  Dim ms As MemoryStream = New MemoryStream
  Dim cs As CryptoStream = New CryptoStream _
     (ms, sa.CreateEncryptor(), CryptoStreamMode.Write)
  Dim plainbytes() As Byte = Encoding.ASCII.GetBytes(message)
  cs.Write(plainbytes, 0, plainbytes.Length)
  cs.Close()
  cipherbytes = ms.ToArray()
  ms.Close()
  returnMessage = Convert.ToBase64String(cipherbytes)

  Return returnMessage

    End Function

Code:
Public Function decrypt(ByVal message As String) As String

  Dim returnMessage As String
  Dim Key As String = "PHDPqfwE3z25f2UYjwwfwg4XSqxvl8WYmy+2h8t6AUg="
  Dim IV As String = "pd5mgMMfDI2Gxm/SKl5I8A=="
  Dim Mode As CipherMode = CipherMode.CBC
  Dim Padding As PaddingMode = PaddingMode.PKCS7
  Dim cipherbytes() As Byte = ASCIIEncoding.ASCII.GetBytes(message)
  cipherbytes = Convert.FromBase64String(message)
  Dim sa As SymmetricAlgorithm = Rijndael.Create()
  sa.Key = Convert.FromBase64String(Key)
  sa.IV = Convert.FromBase64String(IV)
  sa.Mode = Mode
  sa.Padding = Padding
  Dim ms As MemoryStream = New MemoryStream(cipherbytes)
  Dim cs As CryptoStream = New CryptoStream _
     (ms, sa.CreateDecryptor(), CryptoStreamMode.Read)
  Dim plainbytes() As Byte = New Byte(cipherbytes.Length) {}
  cs.Read(plainbytes, 0, plainbytes.Length)
  cs.Close()
  cipherbytes = ms.ToArray()
  ms.Close()

  returnMessage = Encoding.ASCII.GetString(plainbytes)

  Return returnMessage

    End Function

Ok I finally got this to work can someone PLEASE tell me if this would be a good en/decryption function, I really need feedback and ideas.

Thanks
~ Digital-Punk
Reply
#2
xor or rc4

are good cyphers.

dont use anything without a key

very weak.
Reply
#3
(08-07-2010, 02:11 AM)BlaiR Wrote: xor or rc4

are good cyphers.

dont use anything without a key

very weak.

Rc4 requires a key correct me if Im wrong.

function rc4(secretmessage, secretKey)
do rc4 encryption
end function

I do believe XoR does not require a key
~ Digital-Punk
Reply
#4
(08-07-2010, 04:11 AM)algorithm Wrote: Rc4 requires a key correct me if Im wrong.

function rc4(secretmessage, secretKey)
do rc4 encryption
end function

I do believe XoR does not require a key


xor does require a key.
Reply
#5
All good ones require a key Tongue
[Image: blanktemplate.png]
Reply
#6
Is it me or isn't this working >>
My only goal is to help other people .
[Image: gNQgw]
How to make a Photo Viewer [HQ]
Reply
#7
Use it like this.

Code:
textbox.text = encrypt(textbox1.text)
Reply
#8
dim Mode As CipherMode = CipherMode.CBC
Dim Padding As PaddingMode = PaddingMode.PKCS7
That gives errors >>
My only goal is to help other people .
[Image: gNQgw]
How to make a Photo Viewer [HQ]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Function] Check For Prime - C# Source AceInfinity 0 1,042 03-31-2012, 07:00 AM
Last Post: AceInfinity
  [Source] TripleDES String Encryption / Decryption euverve 2 3,342 05-13-2011, 10:35 AM
Last Post: Imports System.Net
  [Source] Encrypt/Decrypt a string using Data Encryption Standard (DES) algorithm euverve 0 1,998 05-12-2011, 08:43 PM
Last Post: euverve
  Generate Random Numbers & Letters [ Small Function ] MYPE 22 4,146 04-02-2011, 05:25 PM
Last Post: Pyratepig
  [Help] [VB.NET 2008] Textbox Contents Encryption. Example 4 4,001 02-23-2011, 01:16 AM
Last Post: Example

Forum Jump:


Users browsing this thread: 1 Guest(s)