How to decrypt token string in .net7 project, encrypted by owin middleware with web.config machineKey

98 views Asked by At

I know that token string encrypted with AES. I have got section in web.config with machineKey like this

<system.web>
    <machineKey decryptionKey="{decryptionKey}" validationKey="{validationKey}" />
</system.web>

Is it possible to decrypt it with DataProtection in .net7 project knowing machineKey values? If yes, then how it has to be configured?

And how it can be solved using AesCryptoProvider?

if it not possible in net7 project, how it can be solved in net framework project?

1

There are 1 answers

0
Xecrets On

Everything is possible, more or less, but sometimes it gets complicated.

Please clarify your use case much more precisely. Just what are you trying to achieve?

In general you can always reverse-engineer (or in many cases check out the Microsoft reference sources) the code.

But typically, the whole point of using MachineKey-encryption in ASP.NET is for roundtrips via browser to yourself. I.e. it's not typically intended that things encrypted with a MachineKey should be decrypted somewhere else (except for example members of a load sharing cluster, in which case you must ensure the MachineKey is set to the same value in all members).

That being said, if you have good enough reason, you can of course duplicate the code necessary to decrypt things, as long as you also have access to the actual MachineKey - which is not necessarily easy unless it is explicitly set in web.config et. al.

You can start checking the reference source for MachineKey here: https://referencesource.microsoft.com/#System.Web/Security/MachineKey.cs,d6594833e109d2fb or just use ILSpy https://github.com/icsharpcode/ILSpy .