|
byte[] CryptographicKey = Convert.FromBase64String(txtCK.Text);<br />
byte[] IVector = new byte[16];
Array.Copy(CryptographicKey, IVector, 16);
<br />
RijndaelManaged AES256 = new RijndaelManaged();<br />
AES256.KeySize = 256;<br />
AES256.Mode = CipherMode.CBC;<br />
ICryptoTransform Encryptor = AES256.CreateEncryptor(CryptographicKey, IVector);<br />
<br />
Ciphertext = new FileStream(txtOutputPath.Text, FileMode.Create, FileAccess.Write, FileShare.None);<br />
CryptoStream CStreamWriter = new CryptoStream(Ciphertext, Encryptor, CryptoStreamMode.Write);<br />
<br />
CStreamWriter.Write(Plaintext, 0, Plaintext.Length);
CStreamWriter.FlushFinalBlock();<br />
<br />
Ciphertext.Close();<br />
CStreamWriter.Close();
CStreamWriter.Write(Plaintext, 0, Plaintext.Length); //OUT OF MEMORY EXCEPTION HERE
The code works fine for files smaller than 150mb, but when I tried to encrypt a 300mb file. I got that exception. I have 3gb of ram and when I started the encryption, my usage is only at 30%.
What seems to be the problem?
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Allocating a memory block of 300M at a time is not a good idea...
Try to split the file into smaller pieces and then encrypt.
|
|
|
|
|
Will the output still be the same?
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Yes, if each piece is encrypted with the same key and IV.
And remember to use the same size to decrypt.
Sample:
<br />
FileStream fs = new FileStream(f, FileMode.Open);<br />
byte[] data=new byte[1024];<br />
while (true)<br />
{<br />
int i = fs.Read(data, 0, 1024);<br />
if (i <= 0)<br />
break;<br />
else<br />
{<br />
CStreamWriter.Write(data, 0, 1024);
CStreamWriter.FlushFinalBlock();<br />
}<br />
}<br />
modified on Sunday, May 11, 2008 7:19 AM
|
|
|
|
|
Thanks! I'll give it a try.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
If i have any number like : 1234
and i want to do 1+2+3+4 = 10
What should i do? and what method should i use ?
-Thanks
Peter
|
|
|
|
|
string number="1234";<br />
int total=0;<br />
<br />
for(int i=0;i<number.length;i++)><br />
{<br />
total+=Int32.Parse(number);<br />
}</number.length;i++)>
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Thanks
i think this is really tricky..any other way you can solve this ?
Peter
|
|
|
|
|
How is it "tricky"?
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Here is a method that can work, should in theory also be able to add numbers in string with chars.
<code>
string s = "1234";
int total = 0;
foreach (char c in s)
{
int x;
int.TryParse(c.ToString(), out x);
total += x;
}
</code>
|
|
|
|
|
..and the shortest one:
<br />
string s = "1234";<br />
int total = s.ToCharArray().Sum((x) => int.Parse(x.ToString()));<br />
|
|
|
|
|
Naaah
int total = s.ToCharArray().Sum((x) => ((int)x)-48);
(ok ok , it is more of a hack )
|
|
|
|
|
But you can still leave out the brackets around x :P
|
|
|
|
|
You should use the modulus or remainder function and integer division to solve this problem. Using a divisor of 10 you extract one decimal digit at a time from the number. The same technique with a divisor of 16 can be used to extract hexdecimal digits.
Int32 num = 123456789;
Int32 sum = 0;
Int32 temp = num;
while (temp > 0) {
sum += temp % 10;
temp = temp / 10;
}
Console.WriteLine("Sum of all digits in {0} is {1}", num, sum);
AlanN
|
|
|
|
|
Hi! Me and some people have formed a small development team called Condemned Entertainment for making games but we ran into a snag. We have no people who know C# and the engine we are using uses C# wondering if we can get some help if someone can help set us up. my name is Midias on the forums and our leader is Craka_J the forums is: http://www.condemnedentertainment.webs.com/index.html thanks.
|
|
|
|
|
Well you could look to my sig.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
well thx for replying but as it turns out we found a better game engine and it requires C++ so unless u know C++ now lol thank you.
|
|
|
|
|
How do you get a list of all the computers on the network in C#? What I want is a network machine selection dialog similar to Windows Network Browsing window...
|
|
|
|
|
|
hi
i want to work with TableAdapters programmatically, can anyone guide me by article or sample ?
thanks
|
|
|
|
|
|
Can any one tell me that how can I get the server name from a lan based network? I mean suppose the C# .exe file runs on a client pc but the server is on one of the network pc. How can I dynamically get the pc name in which the server is installed? I don't want to change my internal code for this. If there is any way that i can read the server as well the pc name on a lan based network?
|
|
|
|
|
Two problems... What kind of server?? and if you don't want to change your code, how on earth is your code going to discover the server name??
|
|
|
|
|
Now what I do is read the pc name in which the server is installed on the network from a notepad where I write the pc name. Now is thr any way to read this from network or the pc name from the network dynamically?
|
|
|
|
|
If the file is sitting in a network share properly setup with appropriate permissions, yes, the PC can read the file. But, the prerequesite here is to understand Windows Networking. If you don't, this is going to be quite a difficult task for you.
Reading a file is easy since it's no different than reading a file from a local drive. The only thing that changes is how you specify the filename. The UNC path would normally be something like:
\\serverName\shareName\folder\fileName
|
|
|
|