Invalid length for a Base-64 char array

Posted on 2006-05-24
Last Modified: 2008-01-09
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 ?

Question by:parveenmehta
    LVL 41

    Expert Comment

    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
    LVL 41

    Expert Comment

    ...oops I was wrong... Base64 has a "block size" of 4

    How was the original string created?
    LVL 32

    Accepted Solution

    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.

    Author Comment

    well the length of the string i have generated is 90.
    Here is the code that i used to generate the string.
    where ConnectionString is the SQL connection string from web.config


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This is about my first experience with programming Arduino.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now