Storing an Encrypted file in database

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

Storing an Encrypted file in database

 
0
  #1
Apr 19th, 2008
Hi, I was just wondering if anybody new of a way to store an encrypted file to an sql server database through a stored procedure. I have managed to encrypt a file selected from a FileUpload control but at the minute the encrypted file and the key are created and saved locally to the machine.

What I would like to be able to achieve is: under the one submit button have the file encrypted and then store the encrypted file and key to the database or force user A to browse for these files before submitting.

However, on execution I am getting an error stating that Input string was not in correct format and it is bugging out at the following line:

  1. submitCommand.ExecuteReader();

Below is a section of the code that I am using to try to save the encrypted file and key to the database (as varbinary)

  1. byte[] blobEcryptedFile = FileUpload_EncryptedFile.FileBytes;
  2. blobFile = blobEcryptedFile;
  3.  
  4. byte[] blobPKey = FileUpload_Key.FileBytes;
  5. blobKey = blobPKey;
  6.  
  7. //Actual filename of the file
  8. string filename = FileUpload_submitAss.FileName;
  9.  
  10. submitCommand.Parameters.Add(new SqlParameter("@assignment", SqlDbType.VarBinary, blobFile.Length, ParameterDirection.Input, false, 0, 0, "Assignment", DataRowVersion.Current, blobFile));
  11. submitCommand.Parameters["@assignment"].Value = blobFile; //The path to the encrypted file
  12.  
  13. submitCommand.Parameters.Add(new SqlParameter("@filename", SqlDbType.NVarChar, 50, "Filename"));
  14. submitCommand.Parameters["@filename"].Value = filename;
  15.  
  16. submitCommand.Parameters.Add(new SqlParameter("@publicKey", SqlDbType.VarBinary, blobKey.Length, ParameterDirection.Input, false, 0, 0, "pKey", DataRowVersion.Current, blobKey));
  17. submitCommand.Parameters["@publicKey"].Value = blobKey; //The path to the key
  18.  
  19. submitCommand.ExecuteReader();
  20. submitCommand.Dispose();
  21. myConnection.Close();
  22.  
  23. lbl_validation_submitAssignment.Text = "Your file has successfully been uploaded!";

Has anybody any ideas??
Last edited by Elmo_loves_you; Apr 19th, 2008 at 3:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 1
Reputation: Saravanan M is an unknown quantity at this point 
Solved Threads: 0
Saravanan M Saravanan M is offline Offline
Newbie Poster

Re: Storing an Encrypted file in database

 
0
  #2
Nov 22nd, 2008
Error : Input String was not in correct format.

Try this :

1. First set the parameter name and sql data type for sqlcommand.
2. Set value for the parameter name.

Ex:

  1. sqlcommand.Parameters.Add("@Name",sqlDbType.varchar)
  2. sqlcommand.Parameters("@Name").value = value

Hope this will resolve your issue.

Share the knowledge and increase it....
Last edited by peter_budo; Nov 28th, 2008 at 1:05 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC