473,770 Members | 3,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FormsAuthentica tion.Decryption problem

Can you help me to solve the following problem?
on my loggin page I have the code:

protected void LoginButton_Cli ck(object sender, EventArgs e)
{
if(Membership.V alidateUser(TXT Usuario.Text, TXTSenha.Text))

{

if (CBLembra.Check ed)
{
FormsAuthentica tionTicket ticket = new
FormsAuthentica tionTicket(1,TX TUsuario.Text,
DateTime.Now,Da teTime.Now.AddD ays(7),true,"Co okieUsuario") ;
HttpCookie OuttaBiscoito = new
HttpCookie("Out taBiscoito");
OuttaBiscoito.V alue =
System.Web.Secu rity.FormsAuthe ntication.Encry pt(ticket);
OuttaBiscoito.E xpires = DateTime.Now.Ad dDays(7);
Response.Cookie s.Add(OuttaBisc oito);

}
else
{
Response.Cookie s.Remove("Outta Biscoito");
}

FormsAuthentica tion.RedirectFr omLoginPage(TXT Usuario.Text,
false );

}

on my Global.asax:

protected void Session_Start(o bject sender, EventArgs e)
{

HttpCookie OuttaBiscoito = Request.Cookies["OuttaBisco ito"];
if (OuttaBiscoito != null)
{
FormsAuthentica tionTicket ticket =
FormsAuthentica tion.Decrypt(Ou ttaBiscoito.Val ue);
FormsAuthentica tion.SetAuthCoo kie(ticket.Name ,
false, ticket.CookiePa th);
FormsAuthentica tionTicket ticket2 = new
FormsAuthentica tionTicket(1, ticket.Name, DateTime.Now,
DateTime.Now.Ad dDays(7), true, "CookieUsuario" );
OuttaBiscoito.V alue =
FormsAuthentica tion.Encrypt(ti cket2);
OuttaBiscoito.E xpires = DateTime.Now.Ad dDays(7);
Response.Cookie s.Add(OuttaBisc oito);
}
}

If i loggin and exit browser when i acess again it goes OK, but only in a
few minutes. If i exit the browser and wait about half an hour to acess, the
following error is showed:

Server Error in '/outtacom' Application.
--------------------------------------------------------------------------------

Padding is invalid and cannot be removed.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Security .Cryptography.C ryptographicExc eption:
Padding is invalid and cannot be removed.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:
[CryptographicEx ception: Padding is invalid and cannot be removed.]
System.Security .Cryptography.R ijndaelManagedT ransform.Decryp tData(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer,
Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) +1545747
System.Security .Cryptography.R ijndaelManagedT ransform.Transf ormFinalBlock(B yte[]
inputBuffer, Int32 inputOffset, Int32 inputCount) +257
System.Security .Cryptography.C ryptoStream.Flu shFinalBlock() +30
System.Web.Conf iguration.Machi neKeySection.En cryptOrDecryptD ata(Boolean
fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean
useValidationSy mAlgo) +164
System.Web.Secu rity.FormsAuthe ntication.Decry pt(String encryptedTicket )
+242
AdminSite.Globa l.Session_Start (Object sender, EventArgs e) in
Global.asax.cs: 29
System.Web.Sess ionState.Sessio nStateModule.Ra iseOnStart(Even tArgs e)
+2221855
System.Web.Sess ionState.Sessio nStateModule.Co mpleteAcquireSt ate() +159
System.Web.Sess ionState.Sessio nStateModule.Be ginAcquireState (Object
source, EventArgs e, AsyncCallback cb, Object extraData) +518
System.Web.Asyn cEventExecution Step.System.Web .HttpApplicatio n.IExecutionSte p.Execute()
+90
System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
completedSynchr onously) +161


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.1434;
ASP.NET Version:2.0.507 27.1434

Aug 28 '08 #1
0 2888

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4765
by: George Durzi | last post by:
When you call FormsAuthentication.SignOut(), is the FormsAuthentication cookie supposed to be destroyed automatically? I'm creating my FormsAuthentication cookie by doing: HttpCookie oCookie = new HttpCookie(FormsAuthentication.FormsCookieName, sTicket); where sTicket is an encrypted FormsAuthenticationTicket. When I create the FormsAuthenticationTicket, I set its isPersistent property to false.
4
1953
by: Jeff B | last post by:
I am having a very perplexing problem with setting the user's roles. I have tried to figure this out for 2 days now. When the user logs in to the site, I retrieve the roles from the database and create a semicolon delimited string listing the roles returned and store them in the forms authentication cookie. Then in the global.asax Application_AuthenticateRequest, I retrieve the FormsAuthenticationTicket from the forms authentication...
3
3606
by: Phil Certain | last post by:
Hi I'm building a site that has publicly available pages and password protected pages. Publicly available pages reside in: /public and password protected pages reside in: /private
2
1816
by: Grant Merwitz | last post by:
Hi, i am using forms authentication in an ASP.NET project I am setting the Forms authentication cookie by using: FormsAuthentication.RedirectFromLoginPage(UserName.Text, false); Now when i review my trace on my page, there are two cookies created that look identical. When i FormsAuthentication.SignOut() they both dissappear. Any ideas as to why two cookies are created?
4
8329
by: Matthias S. | last post by:
Hi there, I've created an application which is using Forms-based authentification. My Login-Button event handler looks somewhat like this: // validate the input, etc... // sUserName holds now the users name FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, sUserName, DateTime.Now, DateTime.Now.AddMinutes(20),false,
5
4855
by: Åženol Akbulak | last post by:
Hello; I use in my web application FormsAuthentication. Also I use Session state (InProc). When a user logged in, I can read Session parameters. (For example Session). Problem is that, when user close the browser window then open a new browser, FormsAuthentication reads from cookie and user logs in. Althought user logged in, session parameter is null.
2
2709
by: rn5a | last post by:
A web.config file has the following code: <configuration> <system.web> <authentication mode="Forms"> <forms name="NETConnectCookie" loginUrl="Login.aspx"> <credentials passwordFormat="SHA1"/> </forms> </authentication> </system.web>
13
3596
by: Tom Andrecht | last post by:
I'm trying to get some encryption/decryption routines going to take care of my data, and while the encryption is working great, I keep running into the message "Padding is invalid and cannot be removed" on the decryption piece. From everything I can see, I am doing things correctly here My code is as follows: private const string PassStr = "MyPrivateKey"; private static readonly byte PassSalt = new byte { Byte Byte Byte Byte Byte};...
9
4817
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc . I didn't test script on windows. Here is the code, please send me your views. <?php /* Mother Eye Chipper with PHP :), Licence:GPL,
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.