Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

C# Byte[] Encryption -


i have byte[] field file contents need encrypt. nothing special or fancy, enough make sure next person gets won't able decode without effort. use encryption comes .net framework 4.0 not need make file bigger is.

i thought reversing array or adding few bytes end...?

if can avoid making array bigger great.

any suggestions?

thanks!

does addition of 1-16 bytes hurt? aes pad default using below method:

    private static void encryptthendecrypt()     {         byte[] message; // fill bytes         byte[] encmessage; // encrypted bytes         byte[] decmessage; // decrypted bytes - s/b same message         byte[] key;         byte[] iv;          using (var rijndael = new rijndaelmanaged())         {             rijndael.generatekey();             rijndael.generateiv();             key = rijndael.key;             iv = rijndael.iv;             encmessage = encryptbytes(rijndael, message);         }          using (var rijndael = new rijndaelmanaged())         {             rijndael.key = key;             rijndael.iv = iv;             decmessage = decryptbytes(rijndael, encmessage);         }     }      private static byte[] encryptbytes(         symmetricalgorithm alg,         byte[] message)     {         if ((message == null) || (message.length == 0))         {             return message;         }          if (alg == null)         {             throw new argumentnullexception("alg");         }          using (var stream = new memorystream())         using (var encryptor = alg.createencryptor())         using (var encrypt = new cryptostream(stream, encryptor, cryptostreammode.write))         {             encrypt.write(message, 0, message.length);             encrypt.flushfinalblock();             return stream.toarray();         }     }      private static byte[] decryptbytes(         symmetricalgorithm alg,         byte[] message)     {         if ((message == null) || (message.length == 0))         {             return message;         }          if (alg == null)         {             throw new argumentnullexception("alg");         }          using (var stream = new memorystream())         using (var decryptor = alg.createdecryptor())         using (var encrypt = new cryptostream(stream, decryptor, cryptostreammode.write))         {             encrypt.write(message, 0, message.length);             encrypt.flushfinalblock();             return stream.toarray();         }     } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -