After Converting a string from Base64 some characters are nothing.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy Kitchen

    #1

    After Converting a string from Base64 some characters are nothing.

    I have encoded a string into Base64 for the purpose of encryption. I
    then later decrypted it and converted it back from Base64 the final
    string returns with four nothing characters.

    "pass" what the result should be
    "pass____ what the result is where each underline char is a nothing
    char.

    I am about to write a function that will remove the nothing chars butI
    would like to know what is causing the problem and simply avoid it
    instead.

    Encoding code:

    Private Shared Function EncodeBase64(By Val message As String) As
    String
    Dim encodeBuffer As Byte() =
    System.Text.Enc oding.Unicode.G etBytes(message )
    Return Convert.ToBase6 4String(encodeB uffer)
    End Function

    Decoding Code:

    Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
    String
    Return System.Text.Enc oding.Unicode.G etString(decode Buffer)
    End Function

    I believe that the encryption is working as intended

    DecodeBase64(De crypt(password, crypto)) is the line that returns the
    wrong string.

    Thanks for any help
    Jeremy

  • Patrice

    #2
    Re: After Converting a string from Base64 some characters are nothing.

    DecodeBase64 does nothing ? You probably forgot to a call to the
    appropriate FromBase64 method...

    ---
    Patrice

    "Jeremy Kitchen" <J.t.Kitchen@gm ail.coma écrit dans le message de news:
    1174658205.0180 99.79260@l77g20 00...legro ups.com...
    >I have encoded a string into Base64 for the purpose of encryption. I
    then later decrypted it and converted it back from Base64 the final
    string returns with four nothing characters.
    >
    "pass" what the result should be
    "pass____ what the result is where each underline char is a nothing
    char.
    >
    I am about to write a function that will remove the nothing chars butI
    would like to know what is causing the problem and simply avoid it
    instead.
    >
    Encoding code:
    >
    Private Shared Function EncodeBase64(By Val message As String) As
    String
    Dim encodeBuffer As Byte() =
    System.Text.Enc oding.Unicode.G etBytes(message )
    Return Convert.ToBase6 4String(encodeB uffer)
    End Function
    >
    Decoding Code:
    >
    Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
    String
    Return System.Text.Enc oding.Unicode.G etString(decode Buffer)
    End Function
    >
    I believe that the encryption is working as intended
    >
    DecodeBase64(De crypt(password, crypto)) is the line that returns the
    wrong string.
    >
    Thanks for any help
    Jeremy
    >

    Comment

    • Branco Medeiros

      #3
      Re: After Converting a string from Base64 some characters are nothing.

      Jeremy Kitchen wrote:
      <backposted/>

      I've seen encryption algorythms that require the plain text size as a
      multiple of some value to work properly. Did you check the encryption
      with a text the same size of the Base64 encoded string to see if it's
      not automatically padding your text? (wild, wild guess, I know)

      HTH.

      Regards,

      Branco.
      I have encoded a string into Base64 for the purpose of encryption. I
      then later decrypted it and converted it back from Base64 the final
      string returns with four nothing characters.
      >
      "pass" what the result should be
      "pass____ what the result is where each underline char is a nothing
      char.
      >
      I am about to write a function that will remove the nothing chars butI
      would like to know what is causing the problem and simply avoid it
      instead.
      >
      Encoding code:
      >
      Private Shared Function EncodeBase64(By Val message As String) As
      String
      Dim encodeBuffer As Byte() =
      System.Text.Enc oding.Unicode.G etBytes(message )
      Return Convert.ToBase6 4String(encodeB uffer)
      End Function
      >
      Decoding Code:
      >
      Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
      String
      Return System.Text.Enc oding.Unicode.G etString(decode Buffer)
      End Function
      >
      I believe that the encryption is working as intended
      >
      DecodeBase64(De crypt(password, crypto)) is the line that returns the
      wrong string.
      >
      Thanks for any help
      Jeremy

      Comment

      • Patrice

        #4
        Re: After Converting a string from Base64 some characters are nothing.

        Also I find a bit weird that you actually see something that is almost the
        original string. Base64 should produce a much more different string.

        That plus the fact that the encoding function returns a string and that the
        decoding function accept a buffer would make me think that you perhaps still
        have a problem between those two functions calls...

        ---
        Patrice

        "Patrice" <http://www.chez.com/scribe/a écrit dans le message de news:
        uMsCekVbHHA.455 2@TK2MSFTNGP05. phx.gbl...
        DecodeBase64 does nothing ? You probably forgot to a call to the
        appropriate FromBase64 method...
        >
        ---
        Patrice
        >
        "Jeremy Kitchen" <J.t.Kitchen@gm ail.coma écrit dans le message de news:
        1174658205.0180 99.79260@l77g20 00...legro ups.com...
        >>I have encoded a string into Base64 for the purpose of encryption. I
        >then later decrypted it and converted it back from Base64 the final
        >string returns with four nothing characters.
        >>
        >"pass" what the result should be
        >"pass____ what the result is where each underline char is a nothing
        >char.
        >>
        >I am about to write a function that will remove the nothing chars butI
        >would like to know what is causing the problem and simply avoid it
        >instead.
        >>
        >Encoding code:
        >>
        >Private Shared Function EncodeBase64(By Val message As String) As
        >String
        > Dim encodeBuffer As Byte() =
        >System.Text.En coding.Unicode. GetBytes(messag e)
        > Return Convert.ToBase6 4String(encodeB uffer)
        >End Function
        >>
        >Decoding Code:
        >>
        >Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
        >String
        > Return System.Text.Enc oding.Unicode.G etString(decode Buffer)
        > End Function
        >>
        >I believe that the encryption is working as intended
        >>
        >DecodeBase64(D ecrypt(password , crypto)) is the line that returns the
        >wrong string.
        >>
        >Thanks for any help
        >Jeremy
        >>
        >
        >

        Comment

        • Jeremy Kitchen

          #5
          Re: After Converting a string from Base64 some characters are nothing.

          On Mar 23, 9:39 am, "Patrice" <http://www.chez.com/scribe/wrote:
          DecodeBase64 does nothing ? You probably forgot to a call to the
          appropriate FromBase64 method...
          >
          ---
          Patrice
          >
          "Jeremy Kitchen" <J.t.Kitc...@gm ail.coma écrit dans le message de news:
          1174658205.0180 99.79...@l77g20 00hsb.googlegro ups.com...
          >
          I have encoded a string into Base64 for the purpose of encryption. I
          then later decrypted it and converted it back from Base64 the final
          string returns with four nothing characters.
          >
          "pass" what the result should be
          "pass____ what the result is where each underline char is a nothing
          char.
          >
          I am about to write a function that will remove the nothing chars butI
          would like to know what is causing the problem and simply avoid it
          instead.
          >
          Encoding code:
          >
          Private Shared Function EncodeBase64(By Val message As String) As
          String
          Dim encodeBuffer As Byte() =
          System.Text.Enc oding.Unicode.G etBytes(message )
          Return Convert.ToBase6 4String(encodeB uffer)
          End Function
          >
          Decoding Code:
          >
          Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
          String
          Return System.Text.Enc oding.Unicode.G etString(decode Buffer)
          End Function
          >
          I believe that the encryption is working as intended
          >
          DecodeBase64(De crypt(password, crypto)) is the line that returns the
          wrong string.
          >
          Thanks for any help
          Jeremy
          That isn't my problem it works it is just that chars with the value
          of nothing are appended to what should be the result. This doens't
          happen if i call the function in immediate mode. It does happen when I
          assign the result to a value.

          I eventually wrote the following code to get around the problem but I
          would like to avoid having it in the first place.

          Cleaner Code:
          Private Shared Function CleanStringOfNo things(ByVal unclean As String)
          As String
          Dim clean As New StringBuilder(u nclean.Length)
          For Each c As Char In unclean
          If c <Nothing Then
          clean.Append(c)
          End If
          Next
          Return clean.ToString
          End Function

          Comment

          • Jeremy Kitchen

            #6
            Re: After Converting a string from Base64 some characters are nothing.

            On Mar 23, 9:45 am, "Patrice" <http://www.chez.com/scribe/wrote:
            Also I find a bit weird that you actually see something that is almost the
            original string. Base64 should produce a much more different string.
            >
            That plus the fact that the encoding function returns a string and that the
            decoding function accept a buffer would make me think that you perhaps still
            have a problem between those two functions calls...
            >
            ---
            Patrice
            >
            "Patrice" <http://www.chez.com/scribe/a écrit dans le message de news:
            uMsCekVbHHA.4.. .@TK2MSFTNGP05. phx.gbl...
            >
            DecodeBase64 does nothing ? You probably forgot to a call to the
            appropriate FromBase64 method...
            >
            ---
            Patrice
            >
            "Jeremy Kitchen" <J.t.Kitc...@gm ail.coma écrit dans le message de news:
            1174658205.0180 99.79...@l77g20 00hsb.googlegro ups.com...
            >I have encoded a string into Base64 for the purpose of encryption. I
            then later decrypted it and converted it back from Base64 the final
            string returns with four nothing characters.
            >
            "pass" what the result should be
            "pass____ what the result is where each underline char is a nothing
            char.
            >
            I am about to write a function that will remove the nothing chars butI
            would like to know what is causing the problem and simply avoid it
            instead.
            >
            Encoding code:
            >
            Private Shared Function EncodeBase64(By Val message As String) As
            String
            Dim encodeBuffer As Byte() =
            System.Text.Enc oding.Unicode.G etBytes(message )
            Return Convert.ToBase6 4String(encodeB uffer)
            End Function
            >
            Decoding Code:
            >
            Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
            String
            Return System.Text.Enc oding.Unicode.G etString(decode Buffer)
            End Function
            >
            I believe that the encryption is working as intended
            >
            DecodeBase64(De crypt(password, crypto)) is the line that returns the
            wrong string.
            >
            Thanks for any help
            Jeremy

            I also have an overload of the Decode that accepts a string.

            Here both decode functions are.
            Private Shared Function DecodeBase64(By Val message As String) As
            String
            Dim decodeBuffer As Byte() = Convert.FromBas e64String(messa ge)
            Return DecodeBase64(de codeBuffer)
            End Function

            Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
            String
            Return
            CleanStringOfNo things(System.T ext.Encoding.Un icode.GetString (decodeBuffer))
            End Function

            Comment

            • Tom Shelton

              #7
              Re: After Converting a string from Base64 some characters are nothing.

              On Mar 23, 8:44 am, "Branco Medeiros" <branco.medei.. .@gmail.com>
              wrote:
              Jeremy Kitchen wrote:
              >
              <backposted/>
              >
              I've seen encryption algorythms that require the plain text size as a
              multiple of some value to work properly. Did you check the encryption
              with a text the same size of the Base64 encoded string to see if it's
              not automatically padding your text? (wild, wild guess, I know)
              >
              HTH.
              >
              Regards,
              >
              Branco.
              >
              Branco - I don't think that is a wild guess at all. In fact, it was
              the very though I had when reading the original post. I believe if
              the OP checks his algorithm he will find that this is the root of his
              issue (I've had the same thing happen to me :)

              --
              Tom Shelton

              Comment

              • Jeremy Kitchen

                #8
                Re: After Converting a string from Base64 some characters are nothing.

                On Mar 23, 9:57 am, "Tom Shelton" <tom_shel...@co mcast.netwrote:
                On Mar 23, 8:44 am, "Branco Medeiros" <branco.medei.. .@gmail.com>
                wrote:
                >
                Jeremy Kitchen wrote:
                >
                <backposted/>
                >
                I've seen encryption algorythms that require the plain text size as a
                multiple of some value to work properly. Did you check the encryption
                with a text the same size of the Base64 encoded string to see if it's
                not automatically padding your text? (wild, wild guess, I know)
                >
                HTH.
                >
                Regards,
                >
                Branco.
                >
                Branco - I don't think that is a wild guess at all. In fact, it was
                the very though I had when reading the original post. I believe if
                the OP checks his algorithm he will find that this is the root of his
                issue (I've had the same thing happen to me :)
                >
                --
                Tom Shelton

                Tom I checked the encryption and I am indeed padding zero bytes in the
                encryption.

                Thanks

                Comment

                • Patrice

                  #9
                  Re: After Converting a string from Base64 some characters are nothing.

                  So try :
                  MsgBox(DecodeBa se64(EncodeBase 64("pass")) = "pass")

                  Return True here so it doesn't look like the problem is the base64
                  encoding/decoding part. If you try a longer word would you have always twice
                  the number of characters ? (unicode vs ansi problem ?).

                  --
                  Patrice

                  "Jeremy Kitchen" <J.t.Kitchen@gm ail.coma écrit dans le message de news:
                  1174661451.5134 31.253840@l75g2 00...legr oups.com...
                  On Mar 23, 9:45 am, "Patrice" <http://www.chez.com/scribe/wrote:
                  Also I find a bit weird that you actually see something that is almost the
                  original string. Base64 should produce a much more different string.
                  >
                  That plus the fact that the encoding function returns a string and that
                  the
                  decoding function accept a buffer would make me think that you perhaps
                  still
                  have a problem between those two functions calls...
                  >
                  ---
                  Patrice
                  >
                  "Patrice" <http://www.chez.com/scribe/a écrit dans le message de news:
                  uMsCekVbHHA.4.. .@TK2MSFTNGP05. phx.gbl...
                  >
                  DecodeBase64 does nothing ? You probably forgot to a call to the
                  appropriate FromBase64 method...
                  >
                  ---
                  Patrice
                  >
                  "Jeremy Kitchen" <J.t.Kitc...@gm ail.coma écrit dans le message de
                  news:
                  1174658205.0180 99.79...@l77g20 00hsb.googlegro ups.com...
                  >I have encoded a string into Base64 for the purpose of encryption. I
                  then later decrypted it and converted it back from Base64 the final
                  string returns with four nothing characters.
                  >
                  "pass" what the result should be
                  "pass____ what the result is where each underline char is a nothing
                  char.
                  >
                  I am about to write a function that will remove the nothing chars butI
                  would like to know what is causing the problem and simply avoid it
                  instead.
                  >
                  Encoding code:
                  >
                  Private Shared Function EncodeBase64(By Val message As String) As
                  String
                  Dim encodeBuffer As Byte() =
                  System.Text.Enc oding.Unicode.G etBytes(message )
                  Return Convert.ToBase6 4String(encodeB uffer)
                  End Function
                  >
                  Decoding Code:
                  >
                  Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
                  String
                  Return System.Text.Enc oding.Unicode.G etString(decode Buffer)
                  End Function
                  >
                  I believe that the encryption is working as intended
                  >
                  DecodeBase64(De crypt(password, crypto)) is the line that returns the
                  wrong string.
                  >
                  Thanks for any help
                  Jeremy

                  I also have an overload of the Decode that accepts a string.

                  Here both decode functions are.
                  Private Shared Function DecodeBase64(By Val message As String) As
                  String
                  Dim decodeBuffer As Byte() = Convert.FromBas e64String(messa ge)
                  Return DecodeBase64(de codeBuffer)
                  End Function

                  Private Shared Function DecodeBase64(By Val decodeBuffer As Byte()) As
                  String
                  Return
                  CleanStringOfNo things(System.T ext.Encoding.Un icode.GetString (decodeBuffer))
                  End Function


                  Comment

                  Working...