encryption

rjhe22

Well-known member
Joined
May 22, 2008
Messages
88
Programming Experience
Beginner
A new class clsLock provides:
1) Encryption
2) Decryption
3) Key Setting from String

The model used is the Triple DES (Data Encryption Standard)

This requires a 24 Byte Key and an 8 Byte Initialization Vector

Both must be known to decrypt

The IV is fixed in the class, but the Key can be changed via KeyFromString Function.

This way a specific key could be used by an application.


The idea is to encrypt things like passwords or other sensitive data in varbinary columns in the database. SQL provides its own encryption but it is generally considered to be weak

Applications can freely use the data but no query, Access or alien application can read the data without knowing

1) The encryption scheme,
2) The 24 byte key as its string or byte version
3) The 8 byte vector

We are protecting the source code and implementing the class as a standalone DLL, so the details are in compiled code and in secured source

can anyone help with this dony no where to start
 
Ive not worked with Encryption yet but usually if your dealing with passwords there should be no need to decrypt. Usually you just has them using a 1 way algorithm and then take the user input and hash that and compare.

Would this be of any help

VB.NET:
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography

Friend Class cTripleDES

    ' define the triple des provider

    Private m_des As New TripleDESCryptoServiceProvider

    ' define the string handler

    Private m_utf8 As New UTF8Encoding

    ' define the local property arrays

    Private m_key() As Byte
    Private m_iv() As Byte

    Public Sub New(ByVal key() As Byte, ByVal iv() As Byte)
        Me.m_key = key
        Me.m_iv = iv
    End Sub

    Public Function Encrypt(ByVal input() As Byte) As Byte()
        Return Transform(input, m_des.CreateEncryptor(m_key, m_iv))
    End Function

    Public Function Decrypt(ByVal input() As Byte) As Byte()
        Return Transform(input, m_des.CreateDecryptor(m_key, m_iv))
    End Function

    Public Function Encrypt(ByVal text As String) As String
        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) As String
        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()
        ' create the necessary streams

        Dim memStream As MemoryStream = New MemoryStream
        Dim cryptStream As CryptoStream = New _
            CryptoStream(memStream, CryptoTransform, _
            CryptoStreamMode.Write)
        ' transform the bytes as requested

        cryptStream.Write(input, 0, input.Length)
        cryptStream.FlushFinalBlock()
        ' Read the memory stream and convert it back into byte array

        memStream.Position = 0
        Dim result(CType(memStream.Length - 1, System.Int32)) As Byte
        memStream.Read(result, 0, CType(result.Length, System.Int32))
        ' close and release the streams

        memStream.Close()
        cryptStream.Close()
        ' hand back the encrypted buffer

        Return result
    End Function

End Class
VB.NET:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim key() As Byte = _
          {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, _
          15, 16, 17, 18, 19, 20, 21, 22, 23, 24}
        Dim iv() As Byte = {8, 7, 6, 5, 4, 3, 2, 1}

        ' instantiate the class with the arrays
        Dim des As New cTripleDES(key, iv)

        MsgBox("Test String is TEST")
        Dim newEncryptedData As String = des.Encrypt("TEST")
        MsgBox("This comes out as " & newEncryptedData)
        MsgBox("Decrypting " & newEncryptedData)
        Dim decryptedData As String = des.Decrypt(newEncryptedData)
        MsgBox("This comes out as " & decryptedData)

    End Sub
 
is there no easier way to do this as i have the keys in a dll file and i was told all i need to do is make a reference to it
 
Back
Top