[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2716
  • Last Modified:

Invalid length for a Base-64 char array

I am doing this conversion here
byte[] b=Convert.FromBase64String(System.Configuration.ConfigurationSettings.AppSettings["dbConString"].ToString());
Getting this error
Invalid length for a Base-64 char array
Any idea or any solutions ?
Thanks

0
parveenmehta
Asked:
parveenmehta
  • 2
1 Solution
 
grayeCommented:
I'd guess that you have an empty string in your config file...   I mean Base64 isn't like an encryption routine that requires a defined block size
0
 
grayeCommented:
...oops I was wrong... Base64 has a "block size" of 4

How was the original string created?
0
 
jhanceCommented:
What (I think) graye is trying to say is that the length of the input string to the FromBase64String() method must be a multiple of4 characters.  If it's not, you should PAD it to the correct length with 0's.
0
 
parveenmehtaAuthor Commented:
well the length of the string i have generated is 90.
Here is the code that i used to generate the string.
Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(ConnectionString));
where ConnectionString is the SQL connection string from web.config


0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now