Reputation: 666
I Am generating one XMl file(Export Table from database) in One Pc, And Sending this file to Another Pc and than user Importdata from that xml file, I need to Encrypt this File because of Security reason, generally I am using this function ,
public static string Encrypt(string strText, string strEncrKey)
{
//Initialization Vector IV also must be 8 character long.
byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
try
{
// Declare a UTF8Encoding object so we may use the GetByte
// method to transform the plainText into a Byte array.
byte[] bykey = System.Text.Encoding.UTF8.GetBytes(strEncrKey);
byte[] InputByteArray = System.Text.Encoding.UTF8.GetBytes(strText);
System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider(); // Create a new DES service provider
// All cryptographic functions need a stream to output the
// encrypted information. Here we declare a memory stream
// for this purpose.
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(bykey, IV), System.Security.Cryptography.CryptoStreamMode.Write);
// Write the encrypted information to the stream. Flush the information
// when done to ensure everything is out of the buffer.
cs.Write(InputByteArray, 0, InputByteArray.Length);
cs.FlushFinalBlock();
//Return Byte array into Base64 String Format
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
//Return ex.Message
clsLogs.LogError(ex.Message + "|" + ex.TargetSite.ToString() + "|" + ex.StackTrace);
return clsGlobleFunction.errorstring;
}
}
its Work Perfectly , But it Create Problem When Size of File is very Large, for Example my Xml File has showing below data,
<NewDataSet>
<Table>
<Batch_M_id>-1</Batch_M_id>
<RSN>000061483</RSN>
<Parent_RSN />
<Pkg_Location>1</Pkg_Location>
<CompanyId>1</CompanyId>
</Table>
<Table>
<Batch_M_id>-1</Batch_M_id>
<RSN>000062321</RSN>
<Parent_RSN />
<Pkg_Location>1</Pkg_Location>
<CompanyId>1</CompanyId>
</Table>
</NewDataSet>
I need to Export 4lacs RSN number , as per above example Table Tag will repeated 4lacs time, can you please suggest me which type of Encryption is Better for this performance
Upvotes: 1
Views: 234
Reputation: 77364
Generally speaking, XML is bloated. By design. The design consideration was that bloat was okay as tradeoff to readability because bloat can be easily packed. So if you want to transfer an XML file somewhere, pack it. .NET has Zip classes, any other algorithm will probably do fine also. Once your file is a fraction of it's current size, any other operation will be much easier.
If file size is a problem, don't encode your resulting bytes. You got a byte stream. Write it to a file. Do not convert it to text first.
Upvotes: 1