Support Forums
encryption function - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: encryption function (/showthread.php?tid=11038)



encryption function - Digital-Punk - 08-06-2010

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


RE: encryption function - wchar_t - 08-07-2010

xor or rc4

are good cyphers.

dont use anything without a key

very weak.


RE: encryption function - Digital-Punk - 08-07-2010

(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


RE: encryption function - wchar_t - 08-07-2010

(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.


RE: encryption function - mmki - 08-11-2010

All good ones require a key Tongue


RE: encryption function - .Nielz - 08-13-2010

Is it me or isn't this working >>


RE: encryption function - wchar_t - 08-13-2010

Use it like this.

Code:
textbox.text = encrypt(textbox1.text)



RE: encryption function - .Nielz - 08-13-2010

dim Mode As CipherMode = CipherMode.CBC
Dim Padding As PaddingMode = PaddingMode.PKCS7
That gives errors >>