c# - Use MachineKey.Protect Outside of ASP.NET -


i need encrypt cookie outside of asp.net (console app, powershell etc.) since cookie read mvc application needs encrypted same key.

i can use machinekey class outside of asp.net can't specify encryption type or key these outlined in application's web.config doesn't exists in context. since there no config key randomly generated everytime.

how can encrypt data using same decryption key below guaranteed decrypted later mvc application?

<machinekey    validationkey="207fe3b8e01d0ff81871d7f3efc082a14341a7820942d24d3bef8954cae53d860f46fbcdda73f752ce1052d475d442cc8c14fc814739a757d52d152ef5ee179e"   decryptionkey="326c47e59eb1b38aea84dbc9633bb770c318a740e477c82f3a8d9506f030d953"   validation="sha1" decryption="aes"  /> 

some possible ideas.

  1. just use app.config console app , mirror machine key web.config of main project.
  2. grab machine key programatically. need path of machine key (perhaps store in db, windows registry, or somewhere?). msdn has great examples of method.

grabbing key basically:

configuration config = webconfigurationmanager.openwebconfiguration(configpath); machinekeysection configsection = (machinekeysection)config.getsection("system.web/machinekey"); 

then matter of using right method encrypt cookie. keep in mind asp.net membership providers serialize additional data cookie depending on 1 using, may not possible. also, if app uses userdata section of cookie break it.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -