Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Rijndael



Permlink Replies: 1 - Last Post: May 2, 2016 8:32 AM Last Post By: David Keith
grega loboda

Posts: 47
Registered: 2/5/10
Rijndael
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2016 1:48 AM
Hi

It's really not my piece of cake so is there anybody kind enough to show me the souce code to decrypt a file that was enrypted in C#. I'm looking at LockBox but I have no idea how to use that. I have C# code though:

public void EncryptFile(string inputFile, string outputFile)
{

try
{
string password = @"password";
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);

string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

RijndaelManaged RMCrypto = new RijndaelManaged();

CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);

FileStream fsIn = new FileStream(inputFile, FileMode.Open);

int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);

fsIn.Close();
cs.Close();
fsCrypt.Close();
File.Delete(inputFile);
}
catch
{
MessageBox.Show("Encryption failed!", "Error");
}
}

David Keith

Posts: 196
Registered: 12/10/99
Re: Rijndael
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2016 8:32 AM   in response to: grega loboda in response to: grega loboda
I did this years ago with lockbox, only I was working with a string. So
you'll need to start with a stream of bytes from the loaded file, most
likely in a TMemoryStream. Same concept though.

I kind of remember having to modify the source of lockbox to do this, as
it wasn't quite up to standard. Or perhaps it was another kit that I had
to use in conjunction with lockbox...

Regardless if you PM me I'll send you a test project that you can play
with and get an idea at least. I did this in XE, as I recall. Don't
think it will work without mods in the latest versions of D.

d k e i t h a t w e l l s o f t d o t c o m

no spaces in the above, replace a t with @, d o t with .

On 5/2/2016 04:48, grega loboda wrote:
Hi

It's really not my piece of cake so is there anybody kind enough to show me the souce code to decrypt a file that was enrypted in C#. I'm looking at LockBox but I have no idea how to use that. I have C# code though:

public void EncryptFile(string inputFile, string outputFile)
{

try
{
string password = @"password";
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);

string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

RijndaelManaged RMCrypto = new RijndaelManaged();

CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);

FileStream fsIn = new FileStream(inputFile, FileMode.Open);

int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);

fsIn.Close();
cs.Close();
fsCrypt.Close();
File.Delete(inputFile);
}
catch
{
MessageBox.Show("Encryption failed!", "Error");
}
}

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02