نمایش نتایج 1 تا 2 از 2

نام تاپیک: Invalid length for a Base-64 char array

  1. #1
    کاربر دائمی آواتار میلاد قاضی پور
    تاریخ عضویت
    بهمن 1388
    محل زندگی
    اوج بلند
    پست
    768

    Invalid length for a Base-64 char array

    سلام . من از توابع زیر برای انکریپت و دیکریپت استفاده میکنم . در نمونه ای که دوستان ارائه کرده بودن تو سایت این توابع کاملا صحیح کار میکردن و من هم از همون کلاسی که تو اون برنامه نمونه بود استفاده کردم .
    مشکل اینه که وقتی میخوام یوزرنیم و پسورد وارد شده توسط کاربر رو چک کنم اون ارور رو میده.


    public static string EncryptText(string usernameRegsiteredByUser)
    {
    RijndaelManaged rm = new RijndaelManaged();
    byte[] plainText = Encoding.Unicode.GetBytes(usernameRegsiteredByUser );

    string key = "MeeladGhazipour";
    byte[] salt = Encoding.ASCII.GetBytes(key.Length.ToString());
    PasswordDeriveBytes pdb = new PasswordDeriveBytes(key, salt);
    rm.Key = pdb.GetBytes(32);
    rm.IV = pdb.GetBytes(16);
    MemoryStream ms = new MemoryStream();
    CryptoStream cs = new CryptoStream(ms, rm.CreateEncryptor(), CryptoStreamMode.Write);
    cs.Write(plainText, 0, plainText.Length);
    cs.FlushFinalBlock();
    byte[] Chiper = ms.ToArray();
    ms.Close();
    cs.Close();
    string ChipperText = Convert.ToBase64String(Chiper);
    return ChipperText;
    }
    ///////////////////////////////////////////////////////

    public static string DecryptTextٌ(string ChipperText)
    {
    RijndaelManaged rm = new RijndaelManaged();
    byte[] EncryptData = Convert.FromBase64String(ChipperText);
    string key = "MeeladGhazipour";
    byte[] salt = Encoding.ASCII.GetBytes(key.Length.ToString());
    PasswordDeriveBytes pdb = new PasswordDeriveBytes(key, salt);
    ICryptoTransform Decryptor = rm.CreateDecryptor(pdb.GetBytes(32), pdb.GetBytes(16));
    MemoryStream ms = new MemoryStream(EncryptData);
    CryptoStream cs = new CryptoStream(ms, Decryptor, CryptoStreamMode.Read);
    byte[] PlainText = new byte[EncryptData.Length];
    int DecryptCount = cs.Read(PlainText, 0, PlainText.Length);
    ms.Close();
    cs.Close();
    string DecryptoData = Encoding.Unicode.GetString(PlainText, 0, DecryptCount);
    return DecryptoData;
    }


    یوزر نیم و پسورد رو با این کد چک میکنم:



    private void button1_vorud_Click(object sender, EventArgs e)
    {
    if ((textBox1_uname.Text == "") | (textBox2_pass.Text == ""))
    {
    msgs.unCompleteFields();
    }
    else
    {
    try
    {
    bool isValidUname;
    isValidUname = rwd.checkUserPass("SELECT * FROM users where username='"
    +Security.DecryptTextٌ(textBox1_uname.Text.ToStri ng()) + "' and pass='"
    +Security.DecryptTextٌ( textBox2_pass.Text.ToString() )+ "'");
    if (isValidUname == true)
    {
    this.Hide();
    this.DialogResult = DialogResult.OK;
    Form1 form1 = (Form1)Application.OpenForms["Form1"];
    form1.SS_usersnamelabel.Text = this.textBox1_uname.Text;
    }
    }
    catch(Exception ex)
    {

    MessageBox.Show(ex.Message);

    //نمایش پیغام خطا
    msgs.unableToDo();
    }
    }
    }



    public bool checkUserPass(string selectcommand)
    {
    connection = null;
    connection = new SqlConnection(strConnection);
    command = new SqlCommand();
    command.Connection = connection;
    connection.Open();
    command.CommandText=selectcommand;
    datareader=command.ExecuteReader();

    if (datareader.HasRows)
    {
    return true;
    }
    else
    {
    appMessages.invalidUserPass();
    }
    datareader.Close();
    connection.Close();
    return false;
    }


  2. #2
    کاربر دائمی آواتار fjm11100
    تاریخ عضویت
    خرداد 1387
    محل زندگی
    تهران
    سن
    43
    پست
    658

    نقل قول: Invalid length for a Base-64 char array

    فکر کنم توابع را برعکس استفاده کرده ای

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •