public static string EncodePassword(string password, Process process) { byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(password); byte[] encodedBytes = MangleBytes(passwordBytes, process); string encodedPassword; using (MemoryStream _stream = new MemoryStream()) { using (TextCodedStream stream = new TextCodedStream(_stream, true, true)) { stream.Write(encodedBytes, 0, encodedBytes.Length); stream.Flush(); } _stream.Position = 0; encodedPassword = StreamFunctions.ToString(_stream); } return encodedPassword; }
internal static string GeneratePasswordFileName(string prompt, Process process) { int encodeLength = 8; byte[] encodedBytes = new byte[encodeLength]; byte[] promptBytes = ASCIIEncoding.ASCII.GetBytes(prompt); byte[] idBytes = BitConverter.GetBytes((short)process.Id); for (int byteIndex = 0; byteIndex < promptBytes.Length; byteIndex++) { byte value = (byte)(promptBytes[byteIndex] ^ idBytes[byteIndex % idBytes.Length] ^ encodedBytes[byteIndex % encodeLength]); encodedBytes[byteIndex % encodeLength] = value; } string encodedFileName; using (MemoryStream _stream = new MemoryStream()) { using (TextCodedStream stream = new TextCodedStream(_stream, true, true)) { stream.Write(encodedBytes, 0, encodeLength); stream.Flush(); } _stream.Position = 0; encodedFileName = StreamFunctions.ToString(_stream); } return encodedFileName; }