Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.††If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 1st, 2006, 02:31 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bad Data Error

Has anyone ever received the message below when attempting to run an application? Does anyone know what it means?

System.Security.Cryptography.CryptographicExceptio n: Bad Data.


Reply With Quote
  #2 (permalink)  
Old March 4th, 2006, 02:09 AM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The error occurs when I am authenticating users using the code below. The code appears in the global.asax.cs file. The error occurs when it gets to the line:
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(httpcook.Value);



public void WindowsAuthentication_OnAuthenticate(Object sender, WindowsAuthenticationEventArgs e)
{
    WindowsIdentity id = e.Identity;
    string userIdentity = id.Name;
    string[] userRoles;
    string roleStr = "";

    //Make sure user is an authenticated user (use the User class)
    User user = new User();
    int userID = user.ValidateUser(Utilities.ParseUserLogin(userIde ntity));

    //User is not valid
    if (userID == 0)
    {
        Response.Redirect("http://www.google.com");
    }

    //If user is valid, get roles
    user = new User();
    userRoles = user.GetUserRoles(userID);

    // Create a string to persist the roles
    foreach (string role in userRoles)
    {
        roleStr += role;
    }

    FormsAuthenticationTicket authTicket =
        new FormsAuthenticationTicket(
            1,
            userIdentity,
            DateTime.Now,
            DateTime.Now.AddMinutes(60),
            false,
            roleStr);

    //Produces a string containing an encrypted authentication ticket suitable
    //for use in an HTTP cookie, given a FormsAuthenticationTicket.
    string encTicket = FormsAuthentication.Encrypt(authTicket);

    HttpCookie httpcook = new HttpCookie("authCookie", encTicket);
    Response.Cookies.Add(httpcook);

}



protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{

    HttpCookie httpcook = Context.Request.Cookies["authCookie"];
    FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(httpcook.Value);

    GenericIdentity genIdentity = new GenericIdentity(authTicket.Name);
    string[] roles = authTicket.UserData.Split(new char[] {'|'} ); //if more than one role

    GenericPrincipal genPrincipal = new GenericPrincipal(genIdentity, roles);

    //The principal object thus created would be accessed in the application
    //pages before allowing access to the individual functionality
    HttpContext.Current.User = genPrincipal;

}

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Very slow and almost no replies...BAD..!!! zach007 Forum and Wrox.com Feedback 4 December 23rd, 2006 05:48 PM
Bad data when decrypting using RSA scotthcw ASP.NET 2.0 Basics 0 December 8th, 2006 10:10 PM
Why session_register() is bad. nikolai Pro PHP 17 November 21st, 2004 08:35 PM
'bad command or file name' error freddie2165 JSP Basics 6 April 16th, 2004 06:58 PM



All times are GMT -4. The time now is 02:31 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.