Hello, I'm trying to determine why this encryption won't work for binary files. (specifically docx) I can't use a filestream which is what I've read on a few boards and examples because I'm pulling the files from word and posting to a cloud service. Any Ideas? Am I just going about it wrong? TIA, foster public static byte[] Cipher(byte[] PlainText, string InitialVector, string Salt, int KeySize, string PassPhrase, int PasswordIterations, string HashAlgorithm) { byte[] InitialVectorBytes = Encoding.ASCII.GetBytes(InitialVector); byte[] SaltValueBytes = Encoding.ASCII.GetBytes(Salt); System.Security.Cryptography.PasswordDeriveBytes DerivedPassword = new System.Security.Cryptography.PasswordDeriveBytes(PassPhrase, SaltValueBytes, HashAlgorithm, PasswordIterations); byte[] KeyBytes = DerivedPassword.GetBytes(KeySize / 8); System.Security.Cryptography.RijndaelManaged SymmetricKey = new System.Security.Cryptography.RijndaelManaged(); SymmetricKey.Mode = System.Security.Cryptography.CipherMode.CBC; System.Security.Cryptography.ICryptoTransform Encryptor = SymmetricKey.CreateEncryptor(KeyBytes, InitialVectorBytes); System.IO.MemoryStream MemStream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream CryptoStream = new System.Security.Cryptography.CryptoStream(MemStream, Encryptor, System.Security.Cryptography.CryptoStreamMode.Write); CryptoStream.Write(PlainText, 0, PlainText.Length); CryptoStream.FlushFinalBlock(); byte[] CipherTextBytes = MemStream.ToArray(); MemStream.Close(); CryptoStream.Close(); return CipherTextBytes; } public static byte[] Decipher(byte[] CipherText, string InitialVector, string Salt, int KeySize, string PassPhrase, int PasswordIterations, string HashAlgorithm) { byte[] InitialVectorBytes = Encoding.ASCII.GetBytes(InitialVector); byte[] SaltValueBytes = Encoding.ASCII.GetBytes(Salt); System.Security.Cryptography.PasswordDeriveBytes DerivedPassword = new System.Security.Cryptography.PasswordDeriveBytes(PassPhrase, SaltValueBytes, HashAlgorithm, PasswordIterations); byte[] KeyBytes = DerivedPassword.GetBytes(KeySize / 8); System.Security.Cryptography.RijndaelManaged SymmetricKey = new System.Security.Cryptography.RijndaelManaged(); SymmetricKey.Mode =
User 4551756
Posts
-
binary file encryption -
No one teaches PROGRAMMING any moreThe issue is that over the last 30 years, the world has transitioned into a business driven slop fest. Businesses feel that they can create a crappy product and fix it if it's successful. The only problem is that once it's successful, there isn't time to redevelop the product because there's functional improvements to be made. Through legal decisions, the business people that drive the corporations have set the tone for our work environments, which is largely based on the design McDonald's invented of creating systems to control people who act like hosts for the activities that make the few at the top all the money. Haven't we all bought into that we should make all the jobs replacable so that we can easily move around and others can blend in efficiently without having to be inventive? What's great is that they got us to build the system to make us obsolete or braindead, it was too complicated for them to figure out so they figured out how to sell us to do it. In any case, because the underlying quality of a product in undervalued vs the ability to create a shiny object to be consumed by the public or other unweary purchasers, IT departments are not properly supported by the company to create quality platforms unless the workers are willing to sacrifice the majority of their time to the project. And then, after all is said and done, there isn't equal compensation with the people who are driving the business side of things, so after time, the profession has suffered. The veterans that preach good practices of taking 2 days to write this correctly are overturned with 'take the 2 hour hack solution'. So why should anyone be expected learn to program beyond the extent that the corporations that run our society make it worth doing? -Foster "Welcome to McDonald's, can I take your order?" FosterAF@IntotheBlur.org
modified on Tuesday, May 13, 2008 8:05 AM