Solved

Validating a cookie against a machine key

Posted on 2012-03-29
5
302 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now