Solved

Validating a cookie against a machine key

Posted on 2012-03-29
5
308 Views
Last Modified: 2012-04-02
Can someone help me with some code to decrypt a cookie against a machine key stored in my web config.

Thanks.
0
Comment
Question by:sherbug1015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:masterpass
ID: 37785172
Here is an example of how to encrypt/decrypt using the MachineKey

Public Class Crypto
        Public Function Encrypt(plainText As String) As String
            Dim plaintextBytes = Encoding.UTF8.GetBytes(plainText)
            Return MachineKey.Encode(plaintextBytes, MachineKeyProtection.All)
        End Function

        Public Function Decrypt(encryptedValue As String) As String
            Dim decryptedBytes = MachineKey.Decode(encryptedValue, MachineKeyProtection.All)
            Return Encoding.UTF8.GetString(decryptedBytes)
        End Function
    End Class

Open in new window


Hope this helps!
0
 

Author Comment

by:sherbug1015
ID: 37787000
I don't seem to be able to use MachineKey.  I looked it up and it only works in 4.0 or better?  Do you have any code samples that would work in earlier frameworks.

Thanks.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37787986
0
 

Author Comment

by:sherbug1015
ID: 37788715
CodeCruiser:

I have a machine key tag in my web.config that has a validation key, a decryption key and
validation="SHA1" decryption="AES"

A third party is creating an application and will send me a cookie when the user logs into their site and clicks on the link to my website.  The cookie will have username and password encrypted using the machine key located in my web.config.

I must decrypt the cookie, read the information in the cookie and pass it along to be authenticated.  

I don't know how to decrypt the cookie and am looking for help.  

Anything you can share would be appreciated.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37795709
As you have asked another question on the same issue now, I think you should delete this one.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question