473,395 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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(ByVal message As String) As
String
Dim encodeBuffer As Byte() =
System.Text.Encoding.Unicode.GetBytes(message)
Return Convert.ToBase64String(encodeBuffer)
End Function

Decoding Code:

Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return System.Text.Encoding.Unicode.GetString(decodeBuffe r)
End Function

I believe that the encryption is working as intended

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

Thanks for any help
Jeremy

Mar 23 '07 #1
8 2785
DecodeBase64 does nothing ? You probably forgot to a call to the
appropriate FromBase64 method...

---
Patrice

"Jeremy Kitchen" <J.*********@gmail.coma écrit dans le message de news:
11*********************@l77g2000hsb.googlegroups.c om...
>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(ByVal message As String) As
String
Dim encodeBuffer As Byte() =
System.Text.Encoding.Unicode.GetBytes(message)
Return Convert.ToBase64String(encodeBuffer)
End Function

Decoding Code:

Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return System.Text.Encoding.Unicode.GetString(decodeBuffe r)
End Function

I believe that the encryption is working as intended

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

Thanks for any help
Jeremy

Mar 23 '07 #2
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(ByVal message As String) As
String
Dim encodeBuffer As Byte() =
System.Text.Encoding.Unicode.GetBytes(message)
Return Convert.ToBase64String(encodeBuffer)
End Function

Decoding Code:

Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return System.Text.Encoding.Unicode.GetString(decodeBuffe r)
End Function

I believe that the encryption is working as intended

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

Thanks for any help
Jeremy

Mar 23 '07 #3
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:
uM**************@TK2MSFTNGP05.phx.gbl...
DecodeBase64 does nothing ? You probably forgot to a call to the
appropriate FromBase64 method...

---
Patrice

"Jeremy Kitchen" <J.*********@gmail.coma écrit dans le message de news:
11*********************@l77g2000hsb.googlegroups.c om...
>>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(ByVal message As String) As
String
Dim encodeBuffer As Byte() =
System.Text.Encoding.Unicode.GetBytes(message)
Return Convert.ToBase64String(encodeBuffer)
End Function

Decoding Code:

Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return System.Text.Encoding.Unicode.GetString(decodeBuffe r)
End Function

I believe that the encryption is working as intended

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

Thanks for any help
Jeremy


Mar 23 '07 #4
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...@gmail.coma écrit dans le message de news:
1174658205.018099.79...@l77g2000hsb.googlegroups.c om...
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(ByVal message As String) As
String
Dim encodeBuffer As Byte() =
System.Text.Encoding.Unicode.GetBytes(message)
Return Convert.ToBase64String(encodeBuffer)
End Function
Decoding Code:
Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return System.Text.Encoding.Unicode.GetString(decodeBuffe r)
End Function
I believe that the encryption is working as intended
DecodeBase64(Decrypt(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 CleanStringOfNothings(ByVal unclean As String)
As String
Dim clean As New StringBuilder(unclean.Length)
For Each c As Char In unclean
If c <Nothing Then
clean.Append(c)
End If
Next
Return clean.ToString
End Function

Mar 23 '07 #5
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...@gmail.coma écrit dans le message de news:
1174658205.018099.79...@l77g2000hsb.googlegroups.c om...
>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(ByVal message As String) As
String
Dim encodeBuffer As Byte() =
System.Text.Encoding.Unicode.GetBytes(message)
Return Convert.ToBase64String(encodeBuffer)
End Function
Decoding Code:
Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return System.Text.Encoding.Unicode.GetString(decodeBuffe r)
End Function
I believe that the encryption is working as intended
DecodeBase64(Decrypt(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(ByVal message As String) As
String
Dim decodeBuffer As Byte() = Convert.FromBase64String(message)
Return DecodeBase64(decodeBuffer)
End Function

Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return
CleanStringOfNothings(System.Text.Encoding.Unicode .GetString(decodeBuffer))
End Function

Mar 23 '07 #6
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

Mar 23 '07 #7
On Mar 23, 9:57 am, "Tom Shelton" <tom_shel...@comcast.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

Mar 23 '07 #8
So try :
MsgBox(DecodeBase64(EncodeBase64("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.*********@gmail.coma écrit dans le message de news:
11**********************@l75g2000hse.googlegroups. 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...@gmail.coma écrit dans le message de
news:
1174658205.018099.79...@l77g2000hsb.googlegroups.c om...
>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(ByVal message As String) As
String
Dim encodeBuffer As Byte() =
System.Text.Encoding.Unicode.GetBytes(message)
Return Convert.ToBase64String(encodeBuffer)
End Function
Decoding Code:
Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return System.Text.Encoding.Unicode.GetString(decodeBuffe r)
End Function
I believe that the encryption is working as intended
DecodeBase64(Decrypt(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(ByVal message As String) As
String
Dim decodeBuffer As Byte() = Convert.FromBase64String(message)
Return DecodeBase64(decodeBuffer)
End Function

Private Shared Function DecodeBase64(ByVal decodeBuffer As Byte()) As
String
Return
CleanStringOfNothings(System.Text.Encoding.Unicode .GetString(decodeBuffer))
End Function
Mar 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: wenmang | last post by:
Hi, I ma thinking whether to use Base64 encoding to encode the binary content in the XML file. I have done some simple calculations, it seems to me that the size for encoded content increases by...
5
by: Senna | last post by:
Hi, Have a symmetric encryption method that returns a base64 string. I then get the hex representation of that string with the code below public static string Base64ToHex(string input) {...
1
by: scott | last post by:
Hi all, trying to use base64. Ill get right to the problem. I am converting a string into base 64. No problem there. That base64 string can then be converted back to the orignal string. No...
7
by: dlarock | last post by:
I wrote the following to do an MD5 hash. However, I have a problem (I think) with the conversion from the Byte MD5 hash back to string. Watching this through the debugger it appears as if the...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
by: Martin Widmer | last post by:
Hi Folks In my object I am trying to implement a function in order to render the picture to XML (to generate RDL for SQL Server). That Function causes the error mentioned in the subject at the...
1
by: mirandacascade | last post by:
I am attempting to implement a process, and I'm pretty sure that a major roadblock is that I do not understand the nomenclature. The specs indicate that the goal is to calculate a message digest...
9
by: Jeremy Kitchen | last post by:
Are there any library functions that can help me to do this? If necessary I can convert the string to a byte array. I don't want to have to write my own Hex conversion if it isn't necessary. ...
2
by: joe shoemaker | last post by:
I would like to convert url into md5 hash. My question is that md5 hash will create collision at 2^64. If you do long(value,16), where value is the md5 hash string, would value returned from...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.