"The input is not a valid Base-64 string as it contains a non-base 64 character error"

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="border-collapse:collapse; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px i have a got a client/server application. Server and Client communication is encrypted. Server sends encrypted message
to client and client decrypt message and get it.Same as for Clients messages."I m getting sometimes "The input is not a valid Base-64 string as it contains a non-base 64 character " error at
Decrypt method while Converting From Base64 to String. When i have got this error my <span style="white-space:pre kriptoluMetin variables value is "<span style="white-space:pre <span style="white-space:pre <span style="white-space:pre <span style="white-space:pre <span style="white-space:pre <span style="white-space:pre <span style="white-space:pre ".
Maybe this is where my problem starts. <span style="border-collapse:collapse; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px And i could not find a specific thing that occurs this error.I dont know where
and what is the problem.. Here my Decrypt and encrypt codes;

<span style="border-collapse:collapse; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px
<div style="color:black; background-color:white
<pre> <span style="color:blue public <span style="color:blue string Kripto(<span style="color:blue string duzMetin)
{
<span style="color:blue byte[] baslangicVektorBytes = Encoding.UTF8.GetBytes(baslangicVektor);
<span style="color:blue byte[] saltDegerBytes = Encoding.UTF8.GetBytes(saltDeger);

<span style="color:blue byte[] duzMetinBytes = Encoding.UTF8.GetBytes(duzMetin);

PasswordDeriveBytes sifre = <span style="color:blue new PasswordDeriveBytes(parola, saltDegerBytes, hashAlgoritma, sifreTekrar);

<span style="color:blue byte[] anahtarBytes = sifre.GetBytes(anahtarBoyut / 8);

RijndaelManaged simetrikAnahtar = <span style="color:blue new RijndaelManaged();

simetrikAnahtar.Mode = CipherMode.CBC;

ICryptoTransform kriptocu = simetrikAnahtar.CreateEncryptor(anahtarBytes, baslangicVektorBytes);


MemoryStream hafizaStream = <span style="color:blue new MemoryStream();


CryptoStream kriptoStream = <span style="color:blue new CryptoStream(hafizaStream, kriptocu, CryptoStreamMode.Write);

kriptoStream.Write(duzMetinBytes, 0, duzMetinBytes.Length);


kriptoStream.FlushFinalBlock();


<span style="color:blue byte[] kriptoluMetinBytes = hafizaStream.ToArray();


hafizaStream.Close();
kriptoStream.Close();


<span style="color:blue string kriptoluMetin = Convert.ToBase64String(kriptoluMetinBytes);


<span style="color:blue return kriptoluMetin;
}


<span style="color:blue public <span style="color:blue string Dekripto(<span style="color:blue string kriptoluMetin)
{

<span style="color:blue byte[] baslangicVektorBytes = Encoding.UTF8.GetBytes(baslangicVektor);
<span style="color:blue byte[] saltDegerBytes = Encoding.UTF8.GetBytes(saltDeger);


<span style="color:green //byte[] sifreBytes = Convert.FromBase64String(kriptoluMetin.Replace(" ", "+"));

<span style="color:blue byte[] sifreBytes = Convert.FromBase64String(kriptoluMetin);
PasswordDeriveBytes sifre = <span style="color:blue new PasswordDeriveBytes(parola, saltDegerBytes, hashAlgoritma, sifreTekrar);


<span style="color:blue byte[] anahtarBytes = sifre.GetBytes(anahtarBoyut / 8);


RijndaelManaged simetrikAnahtar = <span style="color:blue new RijndaelManaged();


simetrikAnahtar.Mode = CipherMode.CBC;


ICryptoTransform deKripto = simetrikAnahtar.CreateDecryptor(anahtarBytes, baslangicVektorBytes);


MemoryStream hafizaStream = <span style="color:blue new MemoryStream(sifreBytes);


CryptoStream kriptoStream = <span style="color:blue new CryptoStream(hafizaStream, deKripto, CryptoStreamMode.Read);


<span style="color:blue byte[] duzMetinBytes = <span style="color:blue new <span style="color:blue byte[sifreBytes.Length];


<span style="color:blue int kriptosuzByteSayisi = kriptoStream.Read(duzMetinBytes, 0, duzMetinBytes.Length);


hafizaStream.Close();
kriptoStream.Close();


<span style="color:blue string duzMetin = Encoding.UTF8.GetString(duzMetinBytes, 0, kriptosuzByteSayisi);


<span style="color:blue return duzMetin;
}
[/code]

<br/>
<br/>

<
..!<br/>
<br/>
<br/>

View the full article
 
Back
Top