Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi all,
 
When i try to decrypt my password which is stored in binary(16),null datatype in DB, it gives me error like 'Invalid length for a Base-64 char array.'.
 
i try the below code from one of the asp.net forum.
 
public string DecryptPassowrd(object obj)
{
    string password = obj.ToString();
    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
    System.Text.Decoder utf8Decode = encoder.GetDecoder();
    byte[] todecode_byte = Convert.FromBase64String(password);
    int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
    char[] decoded_char = new char[charCount];
    utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
    string result = new String(decoded_char);
    return result;
}

I got the error at byte[] todecode_byte = Convert.FromBase64String(password); line.

when i googled for that error many of site says to replace " " to "+". but when i did this it gives me another error.

String cannot be of zero length.
Parameter name: oldValue

i am trying to decode "0xA02B92F62E209BC4058E08CF4F6C9689".
 
so what sould i do to overcome this error?

thanks,
krunal
Posted 16-Jul-12 21:58pm
kk20141.8K
Edited 16-Jul-12 22:00pm
v2
Comments
ssd_coolguy at 17-Jul-12 3:11am
   
hei.. i am not sure but this error comes when your string contains any blank space.. that's why you need to replace youre sting with " " to "+".
kkakadiya at 17-Jul-12 4:25am
   
i think there is no blank space in my string i have provided but solution like this given on net. 0x indicating it is hex string.
OriginalGriff at 17-Jul-12 4:52am
   
"so can u give/suggest me code to decrypt the string in normal plain text which i had provided?"
 
Sorry, but no - I have absolutely no idea how you encrypted it.
Start with the code you used to that - it should be fairly clear.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

That doesn't look like a base64 string - it looks like a normal hex number - albeit a bit hex number - and the "0x" prefix does sort of hint at that as well.
 
I would go back to where you stored the information, and look at the process you used to convert it from binary to a format you can store in a DB - then reverse it.
 
BTW: You do realize that Base64 is not an encryption algorithm in nay way, don't you? And that it provides the same security level as printing your data on a T shirt and selling them on Ebay?
  Permalink  
Comments
Sandeep Mewara at 17-Jul-12 4:44am
   
Comment from OP:
 
ok nop.

so can u give/suggest me code to decrypt the string in normal plain text which i had provided?

thanks.
OriginalGriff at 17-Jul-12 4:51am
   
Sorry, but no - I have absolutely no idea how you encrypted it.
Start with the code you used to that - it should be fairly clear.
OriginalGriff at 17-Jul-12 4:52am
   
Sorry Sandeep - I didn't notice it was from you!
Sandeep Mewara at 17-Jul-12 5:37am
   
No problemo! :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

try this it will work
 
public string Decryptdata(string encryptpwd)
{
string decryptpwd = string.Empty;
UTF8Encoding encodepwd = new UTF8Encoding();
Decoder Decode = encodepwd.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
decryptpwd = new String(decoded_char);
return decryptpwd;
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

add an space between ""
 
"" should be " "
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 189
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 27 May 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100