 |
 |

09-30-2009, 07:25 PM
|
|
Freshman
|
|
Join Date: Sep 2009
Posts: 36
|
|
File Encryption
|
I am making a simple program that encrpts a text file and then decrpts it:
Can you please teel me why i get an error when i use this
Public Class Form1
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
System.IO.File.Encrypt(TextBox1.Text)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
System.IO.File.Decrypt(TextBox1.Text)
End Sub
End Class
|
|

09-30-2009, 08:05 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
|
Is it safe for me to assume that Encrypt and Decrypt are existing functions?
What is the error that you get?
|
|

09-30-2009, 08:48 PM
|
|
Freshman
|
|
Join Date: Sep 2009
Posts: 36
|
|
they are existing i get this exact error
Code:
System.IO.IOException was unhandled
Message="The request is not supported. "
|
|

09-30-2009, 10:14 PM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
Take a look at the documentation, particularly the exceptions section:
Quote:
IOException
An I/O error occurred while opening the file.
-or-
This operation is not supported on the current platform.
|
Obviously it's not supported on your platform. My guess is you're not running XP or greater with NTFS as the drive formatting.
|
|

10-01-2009, 04:18 AM
|
|
Freshman
|
|
Join Date: Sep 2009
Posts: 36
|
|
|
i am. i just dont know what im ding wrong there has to be something
|
|

10-01-2009, 08:06 AM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
It's not that your code is trying to do anything wrong. The exception is being thrown because the Encrypt() method doesn't work on all platforms and it's being called on a platform that does not support it. If this is the case, it's likely there's nothing you can do to make it work other than change versions of your operating system.
Are you using Windows XP Home edition? this article says that EFS isn't supported in that. I'd also inspect any settings related to encryption. For example, create a test folder from Windows Explorer and enable encryption in that folder. Can you encrypt/decrypt files in that folder?
If you feel like you've exhausted all options, I suggest filing a bug at http://connect.microsoft.com . If you do so, give them much more detail than you've given us or they'll never address it.
Have you considered using classes from the System.Security.Cryptography namespace to manually encrypt the file? It won't be as easy, but it's much more likely to be supported on your machine.
|
Last edited by AtmaWeapon; 10-01-2009 at 04:23 PM.
|

10-01-2009, 03:50 PM
|
|
Freshman
|
|
Join Date: Sep 2009
Posts: 36
|
|
|
Im on Vista and it should work why would microsoft make a command that dosent work on there latest system. There must be something else thats wrong
|
|

10-01-2009, 04:35 PM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
|
Hmm, doesn't work for me either on Windows 7 64-bit. My guess is there's some system setting that needs to be turned on, but I can't seem to find anything about it.
|
|

10-01-2009, 04:47 PM
|
 |
Centurion
|
|
Join Date: May 2008
Location: Denver, CO USA
Posts: 190
|
|
Would something like this be helpful?
Code:
Private DES As New TripleDESCryptoServiceProvider
Private MD5 As New MD5CryptoServiceProvider
Public Function MD5Hash(ByVal value As String) As Byte()
Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
End Function
Public Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
DES.Key = MD5Hash(key)
DES.Mode = CipherMode.ECB
Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt)
Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
End Function
Public Function Decrypt(ByVal encryptedString As String, ByVal key As String) As String
Try
DES.Key = MD5Hash(key)
DES.Mode = CipherMode.ECB
Dim Buffer As Byte() = Convert.FromBase64String(encryptedString)
Return ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
Catch ex As Exception
MessageBox.Show("Wrong Key Number, decryption not available!")
End Try
End Function
Just encrypt the string before you write to the stream - remember the key must be the same both ways.
|
|

10-01-2009, 07:15 PM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
|

10-01-2009, 08:03 PM
|
|
Freshman
|
|
Join Date: Sep 2009
Posts: 36
|
|
|
it is great i just dont understand it at all..... But thanks anyways and it dosent matter to me if its not secure i just want to try to make it a simple as possible and want to learn what encrpyt decrypt does it must have some use.
|
|

10-01-2009, 08:05 PM
|
 |
Centurion
|
|
Join Date: May 2008
Location: Denver, CO USA
Posts: 190
|
|
|
Ok, good to know, I haven't used this in some time, so what is the newest, shiniest, encryption now?
|
|

10-01-2009, 08:29 PM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
|
I have no idea because I didn't pay much attention in my cryptography class. The article I linked to recommends CBC, but other people also point out that 3DES may be inferior to algorithms like AES.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|