Click here to Skip to main content
15,895,667 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DES Encryption Pin
Randor 16-Dec-11 11:04
professional Randor 16-Dec-11 11:04 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 12:06
professionaljkirkerx16-Dec-11 12:06 
GeneralRe: DES Encryption Pin
Randor 16-Dec-11 13:25
professional Randor 16-Dec-11 13:25 
GeneralRe: DES Encryption Pin
jkirkerx17-Dec-11 8:05
professionaljkirkerx17-Dec-11 8:05 
GeneralRe: DES Encryption Pin
Randor 17-Dec-11 9:47
professional Randor 17-Dec-11 9:47 
GeneralRe: DES Encryption Pin
jkirkerx17-Dec-11 20:49
professionaljkirkerx17-Dec-11 20:49 
GeneralRe: DES Encryption Pin
Randor 18-Dec-11 3:55
professional Randor 18-Dec-11 3:55 
GeneralRe: DES Encryption Pin
jkirkerx18-Dec-11 8:32
professionaljkirkerx18-Dec-11 8:32 
I'm in Huntington Beach CA. I think I'm the only programer in the city.

I was determined to figure it out last night, and went through it with a magnifying glass. Before I crashed, I decided that I should try to write the encryption in vb, so I just converted the one I used to this one that makes more sense to me. The new function produces the same result as the old function to the tee.

Old Function
VB
Public Shared Function Encrypt(ByVal value As String) As String
        If value <> "" Then

            Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
            Dim ms As MemoryStream = New MemoryStream()
            Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), _
            CryptoStreamMode.Write)
            Dim sw As StreamWriter = New StreamWriter(cs)

            sw.Write(value)
            sw.Flush()
            cs.FlushFinalBlock()
            ms.Flush()

            'convert back to a string
            Return Convert.ToBase64String(ms.GetBuffer(), 0, ms.Length)
        Else
            Encrypt = ""
        End If

    End Function



New Function
VB
Public Shared Function _encrypt_DES(ByVal szInputW As String) As String

        Dim szOutput As String = Nothing
        Dim szBufferIn() As Byte = Nothing
        Dim szBufferOut() As Byte = Nothing

        If szInputW <> "" Then
            Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
            With cryptoProvider
                .BlockSize = 64
                .FeedbackSize = 8
                .Key = KEY_64
                .IV = IV_64
                .Mode = CipherMode.CBC
                .Padding = PaddingMode.PKCS7
            End With

            Dim symAlg As SymmetricAlgorithm = cryptoProvider
            Dim xfrm As ICryptoTransform = Nothing

            szBufferIn = UTF8Encoding.UTF8.GetBytes(szInputW)
            xfrm = symAlg.CreateEncryptor()

            szBufferOut = xfrm.TransformFinalBlock(szBufferIn, 0, szBufferIn.Length)
            szOutput = Convert.ToBase64String(szBufferOut, 0, szBufferOut.Length)

        Else
            szOutput = ""
        End If

        Return szOutput

    End Function


I think this is the part I'm missing in my c++ version, perhaps only the final block of the buffer byte array is being run with base64 to create the final encryption product.

szBufferOut = xfrm.TransformFinalBlock(szBufferIn, 0, szBufferIn.Length)
GeneralRe: DES Encryption Pin
Randor 18-Dec-11 11:29
professional Randor 18-Dec-11 11:29 
GeneralRe: DES Encryption Pin
jkirkerx18-Dec-11 14:18
professionaljkirkerx18-Dec-11 14:18 
GeneralRe: DES Encryption Pin
Randor 19-Dec-11 6:19
professional Randor 19-Dec-11 6:19 
GeneralRe: DES Encryption Pin
jkirkerx19-Dec-11 8:06
professionaljkirkerx19-Dec-11 8:06 
GeneralRe: DES Encryption Pin
Randor 19-Dec-11 8:29
professional Randor 19-Dec-11 8:29 
GeneralRe: DES Encryption Pin
jkirkerx19-Dec-11 8:47
professionaljkirkerx19-Dec-11 8:47 
GeneralRe: DES Encryption Pin
jkirkerx19-Dec-11 9:30
professionaljkirkerx19-Dec-11 9:30 
GeneralRe: DES Encryption Pin
Randor 19-Dec-11 10:36
professional Randor 19-Dec-11 10:36 
GeneralRe: DES Encryption Pin
jkirkerx19-Dec-11 10:53
professionaljkirkerx19-Dec-11 10:53 
GeneralPerfect Match! Pin
jkirkerx19-Dec-11 12:13
professionaljkirkerx19-Dec-11 12:13 
GeneralRe: Perfect Match! Pin
Randor 19-Dec-11 14:03
professional Randor 19-Dec-11 14:03 
GeneralRe: Perfect Match! Pin
jkirkerx19-Dec-11 14:49
professionaljkirkerx19-Dec-11 14:49 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 7:59
professionaljkirkerx16-Dec-11 7:59 
AnswerSymmetric-key - Initialization Vector Pin
jkirkerx16-Dec-11 18:04
professionaljkirkerx16-Dec-11 18:04 
GeneralRe: Symmetric-key - Initialization Vector Pin
Chris Losinger17-Dec-11 9:38
professionalChris Losinger17-Dec-11 9:38 
QuestionInterview Preparation Pin
pix_programmer15-Dec-11 18:23
pix_programmer15-Dec-11 18:23 
AnswerRe: Interview Preparation Pin
Chandrasekharan P15-Dec-11 22:07
Chandrasekharan P15-Dec-11 22:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.