Wrox Programmer Forums
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 1st, 2006, 03:31 PM
Authorized User
Join Date: Dec 2003
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.

Old March 4th, 2006, 03:09 AM
Authorized User
Join Date: Dec 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts

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)

    //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(

    //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);


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;


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 06:48 PM
Bad data when decrypting using RSA scotthcw ASP.NET 2.0 Basics 0 December 8th, 2006 11:10 PM
Why session_register() is bad. nikolai Pro PHP 17 November 21st, 2004 09:35 PM
'bad command or file name' error freddie2165 JSP Basics 6 April 16th, 2004 06:58 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.