0
Answer

Need Help with C# crypto package.

aa

aa

15y
3.2k
1
Hi

I am trying to do some initial tests on my hosting site through a sub domain I made but I keep getting this error.

[code]
Server Error in '/' Application.

               The system cannot find the file specified.


                             Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

             Exception Details: System.Security.Cryptography.CryptographicException: The system cannot find the file specified.


             Source Error:

                                                                       Line 24:
Line 25:             // protect the key
Line 26:             key = ProtectedData.Protect(key, null, DataProtectionScope.CurrentUser);
Line 27:
Line 28:                                                                
             Source File: e:\domains\interactivejapanese.com\wwwroot\mytest101\App_Code\generateEncryption.cs    Line: 26            

             Stack Trace:

                                                                       [CryptographicException: The system cannot find the file specified.
]
   System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope) +453
   EncryptedPayPal_API_Credentials.generateEncryption.GenerateKey(String targetPath) in e:\domains\interactivejapanese.com\wwwroot\mytest101\App_Code\generateEncryption.cs:26
   Encryptor.btn_generate_Click(Object sender, EventArgs e) in e:\domains\interactivejapanese.com\wwwroot\mytest101\Encryptor.aspx.cs:22
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
                                                              


[/code]
My code is this:

[code]
 public static string GenerateKey(string targetPath)
        {
          
            // uses default encryption choosen by microsoft - currently it is Rijndael.
            SymmetricAlgorithm Algorithm = SymmetricAlgorithm.Create();
          
            // generate the key
            Algorithm.GenerateKey();

            // store key as bytes
            byte[] key = Algorithm.Key;

            // protect the key
            key = ProtectedData.Protect(key, null, DataProtectionScope.CurrentUser);


            // save the key in a file
            using (FileStream fs = new FileStream(targetPath, FileMode.Create))
            {
                fs.Write(key, 0, key.Length);
            }

            return targetPath;

        }

[/code]So I don't know how to solve this I guess I don't have permisions to use DataScope on my hosting site(not sure if they will give me permisions or what) so is there away around this or something like I really want to use DataScope because I need to protect my files.

Thanks