Problem decrypting connection string on server

Last post 11-08-2007 5:14 PM by byronfromwes92. 1 replies.

Sort Posts:

  • Problem decrypting connection string on server

    11-07-2007, 12:37 PM

    Hi.  I have an ASP.NET app that is built and deployed using MsBuild and a web deployment project.  A requirement for the project is to encrypt the connection string on the production server.  The connection string is not in web.config, but in a file called ConnectionStrings.config (catchy, eh?).

    On the build server, I created a key with a command similar to the following:

    [CODE]
    aspnet_regiis -pc "KeyName" -exp -csp "Microsoft Strong Cryptographic Provider"
    [/CODE]

    I export the key to an XML file with this command:

    [CODE]
    aspnet_regiis -px "KeyName" "c:\KeyName.xml"
    [/CODE]

    I copy the XML file to the production server and then import it with the following command:

    [CODE]
    aspnet_regiis -pi "KeyName" "c:\KeyName.xml"
    [/CODE]

    Back on the build server, I encrypt  the connection strings with the following command:

    [CODE]
    aspnet_regiis -pef "connectionStrings" "c:\inetpub\wwwroot" -prov "ProviderName"
    [/CODE]

    When a deployment occurs, the ConnectionStrings.config file gets copied to the production server with all the other app code.  After the deployment is complete, any attempts to run the app or to manually decrypt the connection strings are met with an error message:

    Parser Error Message: Failed to decrypt using provider 'ProviderName'. Error message from the provider: Bad Data.

    I don't know what I'm missing, but I hope someone can help me.  Thanks!
     


     

  • Re: Problem decrypting connection string on server

    11-08-2007, 5:14 PM
    Answer

    I figured this out on my own.  As it turns out, I was using a similarly named, but incorrect KeyName.xml file for import.

    Cheers,

    Byron

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter