Hi all,
I am simply trying to do a transform to a base 64 string and back, but for
some reason, the FromBase64Trans form is return less bytes than it should. I
have verified that the base64 string is the same length as the one that was
output from ToBase64Transfo rm. I also turned on DoNotIgnoreWhit espaces.
Any ideas?? Here is the code:
// ToBase64
ASCIIEncoding enc = new ASCIIEncoding() ;
byte[] valBytes = enc.GetBytes(va l);
MemoryStream mstr = new MemoryStream();
CryptoStream str = new CryptoStream(ms tr,new
ToBase64Transfo rm(),CryptoStre amMode.Write);
str.Write(valBy tes,0,valBytes. Length);
byte[] buf = mstr.ToArray();
return Convert.ToBase6 4String(buf);
// From Base64
byte[] valBytes = Convert.FromBas e64String(val);
MemoryStream mstr = new MemoryStream();
CryptoStream str = new CryptoStream(ms tr,new
FromBase64Trans form(FromBase64 TransformMode.D oNotIgnoreWhite Spaces),CryptoS t
reamMode.Write) ;
str.Write(valBy tes,0,valBytes. Length);
byte[] buf = mstr.ToArray();
ASCIIEncoding enc = new ASCIIEncoding() ;
return enc.GetString(b uf); 2 5079
On Thu, 5 Feb 2004 12:25:26 -0600, Cole Shelton wrote: Hi all,
I am simply trying to do a transform to a base 64 string and back, but for some reason, the FromBase64Trans form is return less bytes than it should. I have verified that the base64 string is the same length as the one that was output from ToBase64Transfo rm. I also turned on DoNotIgnoreWhit espaces. Any ideas?? Here is the code:
// ToBase64 ASCIIEncoding enc = new ASCIIEncoding() ; byte[] valBytes = enc.GetBytes(va l); MemoryStream mstr = new MemoryStream();
CryptoStream str = new CryptoStream(ms tr,new ToBase64Transfo rm(),CryptoStre amMode.Write); str.Write(valBy tes,0,valBytes. Length);
byte[] buf = mstr.ToArray(); return Convert.ToBase6 4String(buf);
// From Base64 byte[] valBytes = Convert.FromBas e64String(val); MemoryStream mstr = new MemoryStream();
CryptoStream str = new CryptoStream(ms tr,new FromBase64Trans form(FromBase64 TransformMode.D oNotIgnoreWhite Spaces),CryptoS t reamMode.Write) ; str.Write(valBy tes,0,valBytes. Length);
byte[] buf = mstr.ToArray(); ASCIIEncoding enc = new ASCIIEncoding() ; return enc.GetString(b uf);
If all you want to do is switch back and forth between strings, might
something like this work for you?
public static string ToBase64(string asciiText) {
byte[] buffer = ASCIIEncoding.A SCII.GetBytes(a sciiText);
return Convert.ToBase6 4String(buffer) ;
}
public static string FromBase64(stri ng base64Text) {
byte[] buffer = Convert.FromBas e64String(base6 4Text);
return ASCIIEncoding.A SCII.GetString( buffer);
}
HTH,
Tim
--
Tim Smelser - MVP Visual C#
To email me, make the snot hot.
Thanks Tim, that worked. I had tried something similar, but got an error.
Must've been doing something wrong.
Cole
"Tim Smelser" <t_*******@snot mail.com> wrote in message
news:mr******** *************** *****@40tude.ne t... On Thu, 5 Feb 2004 12:25:26 -0600, Cole Shelton wrote:
Hi all,
I am simply trying to do a transform to a base 64 string and back, but
for some reason, the FromBase64Trans form is return less bytes than it
should. I have verified that the base64 string is the same length as the one that
was output from ToBase64Transfo rm. I also turned on DoNotIgnoreWhit espaces. Any ideas?? Here is the code:
// ToBase64 ASCIIEncoding enc = new ASCIIEncoding() ; byte[] valBytes = enc.GetBytes(va l); MemoryStream mstr = new MemoryStream();
CryptoStream str = new CryptoStream(ms tr,new ToBase64Transfo rm(),CryptoStre amMode.Write); str.Write(valBy tes,0,valBytes. Length);
byte[] buf = mstr.ToArray(); return Convert.ToBase6 4String(buf);
// From Base64 byte[] valBytes = Convert.FromBas e64String(val); MemoryStream mstr = new MemoryStream();
CryptoStream str = new CryptoStream(ms tr,new
FromBase64Trans form(FromBase64 TransformMode.D oNotIgnoreWhite Spaces),CryptoS t reamMode.Write) ; str.Write(valBy tes,0,valBytes. Length);
byte[] buf = mstr.ToArray(); ASCIIEncoding enc = new ASCIIEncoding() ; return enc.GetString(b uf);
If all you want to do is switch back and forth between strings, might something like this work for you?
public static string ToBase64(string asciiText) { byte[] buffer = ASCIIEncoding.A SCII.GetBytes(a sciiText); return Convert.ToBase6 4String(buffer) ; }
public static string FromBase64(stri ng base64Text) { byte[] buffer = Convert.FromBas e64String(base6 4Text); return ASCIIEncoding.A SCII.GetString( buffer); }
HTH, Tim -- Tim Smelser - MVP Visual C# To email me, make the snot hot. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: qazmlp |
last post by:
Can anybody comment(& suggest improvements) on the following
implementation that is for
truncating the character buffer contents to the desired length?
Truncating char array
void truncateCharArray(int maxLength , char * buffer )
{
if ((0 == buffer) || !(0 < maxLength))
return;
if (maxLength < strlen(buffer))
|
by: VISHNU VARDHAN REDDY UNDYALA |
last post by:
Hello,
Can someone over here help me in truncating a float variable.
I mean if PI=3.14159 ...How can I get to read the first two or first
three decimal values with out rounding them. Any suggestions are
appreciated. I am BEGINNER TO C PROGRAAMING. Thanks
|
by: VM |
last post by:
How can I truncate a string? For example, if I have a string containing
"Hello All" but the space reserved for this string is of 4 chars, how can I
truncate it to "Hell"? Would I need to create my own method for this or is
there an exisiting String method that does it?
Thanks
|
by: Jitesh Sinha |
last post by:
Hi,
I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal
behaviour of System.Web.mail class. It was truncating the message body
after 3,071 character. The code i was testing was:
Import Namespace="System.Web.Mail"
Dim aa as new StringBuilder(600010)
Dim i as Integer
|
by: Ron |
last post by:
I *just* know there's a function to do this, but I can't
find it:
I want to take the following string:
c:\winnt\23342432sss\2343243ccc\32432432423eeee\2432424cc\t
tt\xxx\tttt\xxx\explorer.exe-ph33334
into something like:
| |
by: DotNetJunkies User |
last post by:
I am calling a VB6 dll from a vb.net windows application that returns an array of strings. My issue is it seems to truncate after a NULL character. For Example VB 6 is returning a string with the HEX value of 4E 31 00 00 01 00 20 20 20 20 20 00 00 00 20 20 20 31 32 30. But when it gets back to Vb.net all I have is 4E 31 or N1. Now I can return the same string as a return value of a function and I get it all.
Please Help,
Patrick Horn...
|
by: rangermccoy |
last post by:
Hello there,
What are the best php/c libraries for handling media including images,
video, and music?
I would like to manipulate media dfiles, including watermarking,
thumbnailing, truncating, etc.
I know there's the GD llibrary for images.
|
by: Daniel Wilson |
last post by:
We have a stored procedure that is giving us an XML representation (using
FOR XML Explicit) of a sales order. Sometimes that evaluats to quite a long
string. Unfortunately, this XML string is being truncated to 2034
characters before we can do anything with it.
Here's our code:
Private Sub LoadXML()Dim dtaXML As New
SqlClient.SqlDataAdapter("MyStoredProcedureThatReturnsXML",
"MyConnectionString")Dim dsXML As New...
|
by: geolemon |
last post by:
I'm having a seriously Twilight Zone moment:
In the code below, I'm building a SQL command into a string variable, declared at the top of my code.
Then, I connect to the database and try to execute the SQL code.
Here's the corresponding snippets:
'declare variables:
Dim strProc As String
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |