Hello!
Is it possible to use the dll in a visual basic application?
Regards,
Adam
AESCrypt.dll in vb.net
- paulej
- Posts: 593
- Joined: Sun Aug 23, 2009 7:32 pm
- Location: Research Triangle Park, NC, USA
- Contact:
Re: AESCrypt.dll in vb.net
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.
Re: AESCrypt.dll in vb.net
Where is the DLL file you are talking about?
- paulej
- Posts: 593
- Joined: Sun Aug 23, 2009 7:32 pm
- Location: Research Triangle Park, NC, USA
- Contact:
Re: AESCrypt.dll in vb.net
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.
Re: AESCrypt.dll in vb.net
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);
}
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);
}
Re: AESCrypt.dll in vb.net
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:
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
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)
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