473,406 Members | 2,698 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,406 software developers and data experts.

Invalid length for a Base-64 char array.

Hi all ,


I am using encryption to encrypt the query string passed from one
page to other. In works fine most of the time but occationally i get this error
-

The line that throws that exception is

Dim cipherTextBytes As Byte()

cipherTextBytes = Convert.FromBase64String(cipherText)

The Error name is

Run-time exception thrown : System.FormatException - Invalid length for a
Base-64 char array.

Its Very Urgent .Please anyone help me wat to do

Thanks in advance
Selvamariapan.c
Nov 8 '08 #1
2 9812
joedeene
583 512MB
Have a look at a similar thread..

with base64, every three bytes (24 bits) of data is converted to four bytes
of printable data (6 bit). when you convert base64 back, you read 4 bytes at
a time and convert back to 3 bytes. you get this error when you don't have a
mulitple of 4. most likely the data is bad, you can append 1 to 3 '='s
to get the correct length (these convert to nulls). you should figure out
why your base64 string are actually invalid.
Basically whatever data you're reading into your byte, it isn't an equal multiple of four, therefore it throws that exception. You can try appending one byte at the end and then test it, if it throws an exception add another byte. You shouldn't have to append more than 3 bytes. And make sure the appended character(s) are something you can tell apart from the rest of them.

joedeene
Nov 8 '08 #2
mldisibio
190 Expert 100+
Joe is correct, but just to clarify, using the quoted post:

- the Base64 standard already stipulates using "=" as the filler character for the last four bytes (so you shouldn't have to make-up your own filler)

and

- (as the previous post said) the exception indicates an underlying problem that the base64 string (that is, the encrypted string) was somehow incorrectly formed to begin with. The base64 encryption algorithm used should already have added this filler while encrypting.

The only reason I emphasize that, is because although Joe's solution would work to eliminate the exception, I would worry about it masking an underlying encryption problem.

Just two cents.

Mike
Nov 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Onder Kaya | last post by:
We have Windows NT 4.0 Oracle 8.1.7 and ORACLE ERP 11.5.8 We created new discrete job. This discrete job contains material requirements and we have custom form which is haz.issue. This form...
2
by: Brian Genisio | last post by:
What is the most reliable way to grab the URL base for a document? I can get window.location.protocol + window.location.host + window.location.path... and that would work most the time, but if...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
12
by: bcr07548 | last post by:
I am writing a web site that uses JavaScript to validate certain forms and I seem to be having some trouble. The site uses PHP and for one of the forms, depending on the situation, one of of the...
0
by: dba123 | last post by:
I am getting the following error when a sub domain is receiving a shared cookie: I have this in both web.config of each application. The 1.1 application does not have the decryption= value...
2
by: ansonee | last post by:
I have the follwoing stored procedure: ALTER procedure .( @ExecutionGUID int = null ) as begin set nocount on declare @s varchar(500) declare @i int
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
1
by: banagani | last post by:
Hi All, I am facing an issue in the XmlTextWriter class in the dotnet 2.0. This is the sample code Actual XML is like this <Name>&#x8A73;&#x7D30;&#x4ED5;&#x69D8;&#x306B;</Name>
3
by: =?Utf-8?B?Vmlub2Q=?= | last post by:
Hi All, I am facing an issue in the XmlTextWriter class in the dotnet 2.0. This is the sample code Actual XML is like this <Name>詳細仕様に</Name>
0
by: parun | last post by:
Hello, is there a possibility to log on to a user whose length is greater than 8 characters. My system is AIX and system base authentication . At IBM I found this information: Limit Windows...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
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...
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
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 projectplanning, coding, testing,...
0
isladogs
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...

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.