Invalid base-64 char array length

I get "Invalid length for Base-64 char array". inside IF () {...} are the options I tried to make it work. it fails in the first line without calling decrypt (...), proving that this is not a problem with functions. I get the same error internally with the first decryption (...) of the call. the latter using encoding.ascii ... will force me to enter the function, but then it does not work inside the function. I get the proper encrypted information from the database into the SSnum string. this value: 4 + mFeTp3tPF

try
{
    string SSnum = dr.GetString(dr.GetOrdinal("Social Security"));
    if (isEncrypted)
    {
      byte[] temp = Convert.FromBase64String(SSnum);
      //SSnum = decrypt(Convert.FromBase64String(SSnum), Key, IV);
      //SSnum = decrypt(Encoding.ASCII.GetBytes(SSnum), Key, IV);
    }
    txt_Social_Security.Text = SSnum;
}
catch { txt_Social_Security.Text = ""; }

I was told to use Convert.FromBase64String () and not the ASCII method ... so why it fails, how can I fix it?

+3
source share
5 answers

: 4 + mFeTp3tPF

, , 4+mFeTp3tPF, Base64.

, , 4+mFeTp3tPF=?

+10

Base64 4 char '=' base64.

string dummyData = imgData.Trim().Replace(" ", "+");
if (dummyData.Length % 4 > 0)
dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
byte[] byteArray = Convert.FromBase64String(dummyData); 

fooobar.com/questions/66552/...

, . suribabu.

+14

, Base64? Base64 - , 7- ASCII. , ASCII, . Base64, Convert.ToBase64String (, , )

( ), , Base64. , Base64 Convert.ToBase64String.

byte[] inputData = ...;

string base64String = Convert.ToBase64String(inputData);

byte[] outputData = Convert.FromBase64String(base64String);

outputData , inputData.

ASCII, System.Text.Encoding.ASCII.GetBytes() , , Base64, .

+1

, 4 + mFeTp3tPF Base64? - - .

0

byte [] temp = Convert.FromBase64String (SSnum);

to that

var temp = UTF8Encoding.UTF8.GetBytes (SSnum);

0
source

Source: https://habr.com/ru/post/1789331/


All Articles