Introduction:
Here I will explain how to solve the problem invalid length for a base-64 char array during decrypt of encrypted password using asp.net.
Description:
Here I will explain how to solve the problem invalid length for a base-64 char array during decrypt of encrypted password using asp.net.
Description:
In previous post I explained clearly how to encrypt and decrypt password using asp.net . After completion code for encrypt and decrypt password if I run the program I get problem like
Invalid length for a base-64 char array
Invalid length for a Base-64 char array. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Invalid length for a Base-64 char array. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
This error occurs during decryption of passwords to eliminate this error I change decrypted code to
Oldone
byte[] todecode_byte = Convert.FromBase64String(encryptpwd); |
To
Newone
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace("","+")); |
After change my code works perfectly. I hope it helps to solve your problem.
Happy Coding………
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
39 comments :
After fixing the code with above said solution another error is being generated as:
String cannot be of zero length.
Parameter name: oldValue
I used this Replace method but another error is being generated "String cannot be of zero length", please provide the solution for the same.
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace("","+"));
please change double quotes to single quotes
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace(' ','+'));
now it will work perfectly
still its not working i have changed double quote to single quote it shows error "Empty Character Literal"
No idea it is not working.
Hi,
I Have one Encrypted string and i want to decrypt that string. I am trying on that i am getting error like this :
Invalid length for a Base-64 char array
this is my string "7W7dA3m7A+GHJHhC5Z8gEg"
can you help this one and mail code for this i tried above code it's also geting error
mail to: v.suri87@gmail.com
check below posts may be it helps you
http://www.aspdotnet-suresh.com/2010/12/introduction-here-i-will-explain-how-to_28.html
and
http://www.aspdotnet-suresh.com/2011/11/encrypt-and-decrypt-configuration.html
Thanks So much Suresh
hi sir
i have changed changed the coding from old one to new new. But still showing a error.
So please give idea what i can do for this.
Hello sir!!!!!
The post for encryption/decryption was cool but
now after changing the code the previous error of "Invalid length for a Base-64 char array"
IS GONE but however now after changing the code it is showing the following error
String cannot be of zero length.
Parameter name: oldValue
Please could you tell what the problem is!!!!
I am getting the same situation as DARR123.
Please help
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace(" ","+"));
try this
suresh garu, pls clarify this
I used this Replace method but another error is being generated "String cannot be of zero length", please provide the solution for the same.
Hello, This is Abu here.
i have tryied with single and double qoatation (encryptpwd.Replace("","+") and (encryptpwd.Replace(' ','+'))). But couldn't find any solution.
could anyone give any solution?
If its possible, Please send me an email here rossyhaider@yahoo.com
Or,
Post here.
Thank you.
Invalid length for a base-64 char array
has been solved but a new error has arise
String cannot be of zero length.
Parameter name: oldValue
please provide solution
still its not working i have changed double quote to single quote it shows error "Empty Character Literal"
please...help
My name is Basudev
I am getting the error in this code
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace("","+")); as
Invalid length for a Base-64 char array
why this error happen Please help me Sir
Hello Sir
i have tryied with single and double qoatation (encryptpwd.Replace("","+") and (encryptpwd.Replace(' ','+'))). But couldn't find any solution.
could anyone give any solution?
Please send me an email here naiemahmad29@gmail.com
Thank you.
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace("","+"));
string cannot be of zeo length
parameter name:old one
Copy following code,this code will work for you .
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace(" ", "+"));
Sir,
I am also getting the same error.Kindly give clarify on this error. Thanks in advance
if getting below type of Error: Put this
byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
protected void gvdecryption_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string decryptpassword = e.Row.Cells[2].Text;
e.Row.Cells[2].Text = Decryptdata(decryptpassword);
}
}
Instead of above:
protected void gvdecryption_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string decryptpassword = e.Row.Cells[1].Text;
e.Row.Cells[1].Text = Decryptdata(decryptpassword);
}
}
not yet find any answer for this.
It works perfectly fine for me even without the Replace(",","+") in the code.
Try to use Encryptdata instead of Decryptdata in your code.
1) Encrypt :: string cipherText = CryptorEngine.Encrypt(FileName.First().ToString(),true);
string FInalFileName= cipherText.Replace("/", "+++");
some string to Encrypt prolblem face :: output directory is invalid .so its problem is Encrlypt key mainly special character "/" is not to allow any file rename.so first of change this name.and whenever you Decrypt time this string to replace actually key data.its working perfectly.after 2 day finally solution.
2) Decrypt ::string FileName= OnlyFileName.First().Replace("+++", "/");
string cipherText = CryptorEngine.Decrypt(FileName, true);
please give space between (" ","+")
it will work
Invalid length for a Base-64 char array
You need to try following:-
Base64 encoding encodes 6 bits per character. So the length of the string, multiplied by 6, must be divisible by 8. If it is not then it doesn't have enough bits to fill every byte and you'll get this exception.
So good odds that encodedMsg just isn't a properly encoded base64 string. You can append some = characters to bypass the exception and see if anything recognizable pops out. The = character is the padding character for base64:
while ((encodedMsg.Length * 6) % 8 != 0) encodedMsg += "=";
So, it's basically unusable until the author helps.
Try using
byte[] todecode_byte = Convert.FromBase64String(encryptpwd.Replace(" ","+"));
use single Quote with space like Convert.FromBase64String(encryptpwd.Replace(' ','+'));
Invalid length for a base-64 char array error during decryption:
In my case i changed the encrypt Password column size in database and it works .
using this command.
byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
For vb.net try the following line you will get solution for "string cannot be of zeo length."
Dim todecode_byte As Byte() = Convert.FromBase64String(encryptpwd.Replace(" "C, "+"C))
Please add this code before you convert the string to FromBase64String.
int mod4 = cipherText.Length % 4;
if (mod4 > 0)
{
cipherText += new string('=', 4 - mod4);
}
FromBase64String need string that devide by 4. If string is not devided by 4 then it throw exception.
For ex
// This string works fine
byte[] b1 = Convert.FromBase64String("test1234");
// Error
byte[] b2 = Convert.FromBase64String("test123");
thanks nandan it's working now..
Note: Only a member of this blog may post a comment.