Generate Key using Cipher Block Chaining MAC

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danishce
    New Member
    • Apr 2007
    • 31

    #16
    I have studied that DES CBC algorithm generate 64 bits (8 byte Hex) encrypted output but when i implement the algorithm in vb.net it gives the same length output as my plain text.i need help on how i obtain 8 byte encrypted output.

    Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
    Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}

    Dim plainText As String
    plainText = "HelloWorldhjsl kajldalkdjlaksj dlakdja"
    Dim DES As New System.Security .Cryptography.D ESCryptoService Provider
    ' Set the cipher mode.
    DES.Mode = System.Security .Cryptography.C ipherMode.CBC
    ' Create the encryptor.
    Dim DESEncrypt As System.Security .Cryptography.I CryptoTransform = DES.CreateEncry ptor(Me.key, Me.iv)
    ' Get a byte array of the string.
    Dim Buffer As Byte() = System.Text.ASC IIEncoding.ASCI I.GetBytes(plai nText)
    ' Transform and return the string.
    Dim keyout As String
    keyout = Convert.ToBase6 4String(DESEncr ypt.TransformFi nalBlock(Buffer , 0, Buffer.Length))

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #17
      Originally posted by danishce
      I have studied that DES CBC algorithm generate 64 bits (8 byte Hex) encrypted output but when i implement the algorithm in vb.net it gives the same length output as my plain text.i need help on how i obtain 8 byte encrypted output.

      Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
      Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}

      Dim plainText As String
      plainText = "HelloWorldhjsl kajldalkdjlaksj dlakdja"
      Dim DES As New System.Security .Cryptography.D ESCryptoService Provider
      ' Set the cipher mode.
      DES.Mode = System.Security .Cryptography.C ipherMode.CBC
      ' Create the encryptor.
      Dim DESEncrypt As System.Security .Cryptography.I CryptoTransform = DES.CreateEncry ptor(Me.key, Me.iv)
      ' Get a byte array of the string.
      Dim Buffer As Byte() = System.Text.ASC IIEncoding.ASCI I.GetBytes(plai nText)
      ' Transform and return the string.
      Dim keyout As String
      keyout = Convert.ToBase6 4String(DESEncr ypt.TransformFi nalBlock(Buffer , 0, Buffer.Length))
      I might be missing something but I do not see a call to ComputeHash().

      Comment

      • danishce
        New Member
        • Apr 2007
        • 31

        #18
        ComputeHash function is available in MD5CryptoServic eProvider Class but in DESCryptoServic eProvider Class ComputeHash is not available instead it will provide ICryptoTransfor m function which uses CreateEncryptor method.

        I studied that DES provide 8 byte output key but unable to generate the output key in 8 byte.waiting for any help?

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #19
          Originally posted by danishce
          I have studied that DES CBC algorithm generate 64 bits (8 byte Hex) encrypted output but when i implement the algorithm in vb.net it gives the same length output as my plain text.i need help on how i obtain 8 byte encrypted output.

          Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
          Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}

          Dim plainText As String
          plainText = "HelloWorldhjsl kajldalkdjlaksj dlakdja"
          Dim DES As New System.Security .Cryptography.D ESCryptoService Provider
          ' Set the cipher mode.
          DES.Mode = System.Security .Cryptography.C ipherMode.CBC
          ' Create the encryptor.
          Dim DESEncrypt As System.Security .Cryptography.I CryptoTransform = DES.CreateEncry ptor(Me.key, Me.iv)
          ' Get a byte array of the string.
          Dim Buffer As Byte() = System.Text.ASC IIEncoding.ASCI I.GetBytes(plai nText)
          ' Transform and return the string.
          Dim keyout As String
          keyout = Convert.ToBase6 4String(DESEncr ypt.TransformFi nalBlock(Buffer , 0, Buffer.Length))
          What does this output? Give us an example.
          What were you expecting? Give us an example.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #20
            You might also consider telling us why you want to do this. You keep telling us what you want to do, the why often helps understand the problem too.

            Comment

            • danishce
              New Member
              • Apr 2007
              • 31

              #21
              Basically i am developing a message interface document and send/receive data to server from my application using winsock TCP/IP. There is a MAC field in the document which apply CBC MAC encryption to plain text that i send to server and return 8 byte key in output.Then i send this 8 byte key with my plain text and the server check my message with their interface. At the server end their is a third party involved which developed server interface so they check my message and gives reply to me either transaction is OK/CANCEL.
              When i am using TripleDES it generate 8 byte MAC Key but i want to generate CBC MAC key using DES.The code for TripleDES key is:
              dim plaintext as string
              plainText = "46546544798752 123449879843132 187984132146546 4"
              Dim data As Byte() = ASCIIEncoding.A SCII.GetBytes(p lainText)
              Dim mac3des As New MACTripleDES
              Dim result As Byte() = mac3des.Compute Hash(data)
              output=(result= 52637299) 8 byte

              Code for DES key is:
              'Dim DES As New DESCryptoServic eProvider
              '' Set the cipher mode.
              'DES.Mode = CipherMode.CBC
              'Dim data As Byte() = ASCIIEncoding.A SCII.GetBytes(p lainText)
              'If key Is Nothing Then
              ' DES.GenerateKey ()
              ' DES.GenerateIV( )
              ' key = DES.Key
              ' iv = DES.IV
              'Else
              ' DES.Key = key
              ' DES.IV = iv
              'End If

              'Dim DESEncrypt As ICryptoTransfor m = DES.CreateEncry ptor()
              'Dim ms As New MemoryStream
              'Dim cs As CryptoStream = New CryptoStream(ms , DESEncrypt, CryptoStreamMod e.Write)
              'cs.Write(data, 0, data.Length)
              'cs.FlushFinalB lock()
              'ms.Position = 0
              'Dim result(ms.Lengt h - 1) As Byte
              'ms.Read(result , 0, ms.Length)
              'cs.Close()
              'Dim keyout As Byte()
              'keyout = result
              output=same length as plain text,i want keyout should be 8 byte.
              I hope you understand this.

              Comment

              Working...