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 "+".

byte[] todecode_byte = Convert.FromBase64String(password.Replace("","+"));

but when i did this it gives me another error.

String cannot be of zero length.
Parameter name: oldValue

so what sould i do to overcome this error?


Hmm... I think binary is wrong since it can only store 0's and 1's
or is that your real purpose?
If not then try using varchar.

hi daniel955,

thanks for the reply.

i am trying to decode "0xA02B92F62E209BC4058E08CF4F6C9689".


This article has been dead for over six months. Start a new discussion instead.