AESCrypt.dll in vb.net

Discussion related to AES Crypt, the file encryption software for Windows, Linux, Mac, and Java.
Post Reply
ada0611
Posts: 1
Joined: Sun Feb 13, 2011 8:55 pm

AESCrypt.dll in vb.net

Post by ada0611 »

Hello!

Is it possible to use the dll in a visual basic application?

Regards,
Adam
User avatar
paulej
Posts: 593
Joined: Sun Aug 23, 2009 7:32 pm
Location: Research Triangle Park, NC, USA
Contact:

Re: AESCrypt.dll in vb.net

Post by paulej »

Possibly, but I've never tried. We do use that DLL from a separate C++ application. I'm not personally familiar with how Visual Basic makes calls into C DLLs.
nkhoury
Posts: 3
Joined: Mon Jul 11, 2011 4:48 pm

Re: AESCrypt.dll in vb.net

Post by nkhoury »

Where is the DLL file you are talking about?
User avatar
paulej
Posts: 593
Joined: Sun Aug 23, 2009 7:32 pm
Location: Research Triangle Park, NC, USA
Contact:

Re: AESCrypt.dll in vb.net

Post by paulej »

It's called "AESCrypt.dll" and it's in the directory where AES Crypt gets installed. You can get the entire source code and change it as necessary to make it useful in your environment. Just download the source from www.aescrypt.com.
maks_pain
Posts: 1
Joined: Fri Sep 07, 2012 3:55 am

Re: AESCrypt.dll in vb.net

Post by maks_pain »

Can someone enlighten me what is the correct way to encrypt & output to actual file.
Am i doing the right thing? I got this error "Cannot read while encrypting"


protected void Page_Load(object sender, EventArgs e)
{
//convert file that need be encrypt into stream
FileStream sr = new System.IO.FileStream("c:\\ItemID.xls", FileMode.Open, FileAccess.ReadWrite);
//encrypt the file
Stream aesStream = new SharpAESCrypt.SharpAESCrypt("1234", sr, SharpAESCrypt.OperationMode.Encrypt);
SaveStreamToFile(aesStream, "c:\\ItemID.xls.aes");
//close stream
sr.Close();
aesStream.Close();
}

public void SaveStreamToFile(Stream stream, string filename)
{
using (Stream destination = File.Create(filename))
Write(stream, destination);
}

public void Write(Stream from, Stream to)
{
for (int a = from.ReadByte(); a != -1; a = from.ReadByte())
to.WriteByte((byte)a);
}
kenkendk
Posts: 5
Joined: Tue Jan 03, 2012 11:04 am

Re: AESCrypt.dll in vb.net

Post by kenkendk »

The error message means that you are reading from a stream that is meant for encrypting.
You should write unencrypted data to a stream that you are encrypting.
The setup is: data -> aes -> file.

The logic is that the AESCrypt instance is a "filter" for the underlying file data, which mimics how encryption is implemented in .Net.

You should do something like this instead:

Code: Select all

using (var sr = new FileStream("c:\\ItemID.xls", FileMode.Open, FileAccess.Read))
using (var sw = new FileStream("c:\\ItemID.aes", FileMode.Open, FileAccess.Write))
using (var aes = new SharpAESCrypt.SharpAESCrypt("1234", sw, SharpAESCrypt.OperationMode.Encrypt))
    sr.CopyTo(aes)
Other notes:
1) This is not VB.NET, it is C# code ?
2) You should add a using statement to ensure that the AES stream is correctly disposed
3) Copying one byte at a time is very bad for performance. You should use a buffer of at least 8kb, or use the CopyTo method in .Net 4.0:
http://stackoverflow.com/questions/2301 ... es-c-sharp
Post Reply