D
d4v3y0rk
i have a class i found/wrote (meaning i found it originally and
tinkered with it to make it mine) and i would like some suggestions on
how to make it better. i am looking for things i need to add,
weaknesses, whatnot. Thanks in advance.
-----------------------------------------------------------------------------------------------------------------
Imports System.Security.Cryptography
Imports System.Security
Imports System.Text
Imports System.IO
Public Class encoder
Private m_des As New TripleDESCryptoServiceProvider
Private m_utf8 As New UTF8Encoding
Private m_key() As Byte
Private m_iv() As Byte = {8, 7, 6, 5, 4, 3, 2, 1}
Public Function Encrypt(ByVal text As String, ByVal strPassword As
String) As String
m_key =
System.Text.Encoding.UTF8.GetBytes(strPassword.PadRight(24, "&"))
Dim input() As Byte = m_utf8.GetBytes(text)
Dim output() As Byte = Transform(input,
m_des.CreateEncryptor(m_key, m_iv))
Return Convert.ToBase64String(output)
End Function
Public Function Decrypt(ByVal text As String, ByVal strPassword As
String) As String
m_key =
System.Text.Encoding.UTF8.GetBytes(strPassword.PadRight(24, "&"))
Dim input() As Byte = Convert.FromBase64String(text)
Dim output() As Byte = Transform(input,
m_des.CreateDecryptor(m_key, m_iv))
Return m_utf8.GetString(output)
End Function
Private Function Transform(ByVal input() As Byte, ByVal
CryptoTransform As ICryptoTransform) As Byte()
Dim memStream As MemoryStream = New MemoryStream
Dim cryptStream As CryptoStream = New CryptoStream(memStream,
CryptoTransform, CryptoStreamMode.Write)
cryptStream.Write(input, 0, input.Length)
cryptStream.FlushFinalBlock()
memStream.Position = 0
Dim result(CType(memStream.Length - 1, System.Int32)) As Byte
memStream.Read(result, 0, CType(result.Length, System.Int32))
memStream.Close()
cryptStream.Close()
Return result
End Function
End Class
-----------------------------------------------------------------------------------------------------------------
tinkered with it to make it mine) and i would like some suggestions on
how to make it better. i am looking for things i need to add,
weaknesses, whatnot. Thanks in advance.
-----------------------------------------------------------------------------------------------------------------
Imports System.Security.Cryptography
Imports System.Security
Imports System.Text
Imports System.IO
Public Class encoder
Private m_des As New TripleDESCryptoServiceProvider
Private m_utf8 As New UTF8Encoding
Private m_key() As Byte
Private m_iv() As Byte = {8, 7, 6, 5, 4, 3, 2, 1}
Public Function Encrypt(ByVal text As String, ByVal strPassword As
String) As String
m_key =
System.Text.Encoding.UTF8.GetBytes(strPassword.PadRight(24, "&"))
Dim input() As Byte = m_utf8.GetBytes(text)
Dim output() As Byte = Transform(input,
m_des.CreateEncryptor(m_key, m_iv))
Return Convert.ToBase64String(output)
End Function
Public Function Decrypt(ByVal text As String, ByVal strPassword As
String) As String
m_key =
System.Text.Encoding.UTF8.GetBytes(strPassword.PadRight(24, "&"))
Dim input() As Byte = Convert.FromBase64String(text)
Dim output() As Byte = Transform(input,
m_des.CreateDecryptor(m_key, m_iv))
Return m_utf8.GetString(output)
End Function
Private Function Transform(ByVal input() As Byte, ByVal
CryptoTransform As ICryptoTransform) As Byte()
Dim memStream As MemoryStream = New MemoryStream
Dim cryptStream As CryptoStream = New CryptoStream(memStream,
CryptoTransform, CryptoStreamMode.Write)
cryptStream.Write(input, 0, input.Length)
cryptStream.FlushFinalBlock()
memStream.Position = 0
Dim result(CType(memStream.Length - 1, System.Int32)) As Byte
memStream.Read(result, 0, CType(result.Length, System.Int32))
memStream.Close()
cryptStream.Close()
Return result
End Function
End Class
-----------------------------------------------------------------------------------------------------------------