Question Triple Des Encrypted key

loukas

New member
Joined
Feb 5, 2010
Messages
2
Programming Experience
Beginner
Hi all
i am working on Triple Des
VB.NET:
Public Class clsCrypto

    Public Shared Function EncryptTripleDES(ByVal sIn As String, ByVal sKey As String) As String
        Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider
        Dim hashMD5 As New System.Security.Cryptography.MD5CryptoServiceProvider

        ' scramble the key
        sKey = ScrambleKey(sKey)
        'Compute the MD5 hash.
        DES.Key = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
        'Set the cipher mode.
        DES.Mode = System.Security.Cryptography.CipherMode.ECB
        'Create the encryptor.
        Dim DESEncrypt As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor()
        'Get a byte array of the string.
        Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(sIn)
        'Transform and return the string.
        Return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
    End Function

    Public Shared Function DecryptTripleDES(ByVal sOut As String, ByVal sKey As String) As String
        Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider()
        Dim hashMD5 As New System.Security.Cryptography.MD5CryptoServiceProvider

        '' scramble the key
        sKey = ScrambleKey(sKey)
        ' Compute the MD5 hash.
        DES.Key = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
        ' Set the cipher mode.
        DES.Mode = System.Security.Cryptography.CipherMode.ECB
        ' Create the decryptor.
        Dim DESDecrypt As System.Security.Cryptography.ICryptoTransform = DES.CreateDecryptor()
        Dim Buffer As Byte() = Convert.FromBase64String(sOut)
        '     Transform and return the string.
        Return System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
    End Function
    Private Shared Function ScrambleKey(ByVal v_strKey As String) As String

        Dim sbKey As New System.Text.StringBuilder
        Dim intPtr As Integer
        For intPtr = 1 To v_strKey.Length
            Dim intIn As Integer = v_strKey.Length - intPtr + 1
            sbKey.Append(Mid(v_strKey, intIn, 1))
        Next

        Dim strKey As String = sbKey.ToString

        Return sbKey.ToString

    End Function

End Class
in form

VB.NET:
Dim encryptKey As String
    Dim dencryptKey As String
dim stringClientKey as string 
stringClientKey="......"
 Dim key As String = "A"

        encryptKey = clsCrypto.EncryptTripleDES(stringClientKey, key)
        FIDTextBox.Text = encryptKey
        dencryptKey = clsCrypto.DecryptTripleDES(FIDTextBox.Text, key)
        SnTextBox.Text = dencryptKey

everything (i believe ) its ok
encryptKey=6NuKtC1BjsJ/M5GW6ARhoeKqjEYGGHNYoX7bSQO+FtWpGp8g/d27C5ZRKjkmyjeDdsz/LYHjcNPLlFXaVXQVq3Iho5NRxJFE

its to much characters 96
(96 bits or 96 bytes?)

the steps are
take encryptKey, decrypted
add 2 more string variables,
encrypt and decrypt (if the new 2 string variables its ok then run program)

is there a way to show it with less characters?
or convert to something alls ?
:confused: :confused: :confused:
 
Last edited:
Encryption will not result in less data, rather the opposite. To transform data into less data without loosing content you have to use compression. For such small amount of data you have there also compression will have no effect, Gzip compressing even a single char will result in 120 bytes because of the algorithm. For example a small text file with 6000 chars may be translated to only 2700 bytes compressed. System.IO.Compression Namespace ()
 
ok thanks
i am in the wrong way.

i am reading

hdSn = clsKeyCreator.GetVolumeSerial.ToString
biosName = clsKeyCreator.getBiosName.ToString

stringKey=hdSn+biosName
step1 i want encrypt stringKey
step2 decrypt stringKey
step3 stringKeySn= (decrypted stringKey)+30(days)
step4 encrypt stringKeySn

is there a way to do this with simple steps?
 
Back
Top