日期:2014-05-16 浏览次数:20921 次
MyClass s = new MyClass();
string strFile = @"C:\db1.rar";
s.ModifyFileHead(strFile, MyClass.OpType.Encode, "abc");
// s.ModifyFileHead(strFile, MyClass.OpType.Decode, "");
class MyClass
{
public MyClass()
{
}
public enum OpType
{
/// <summary>
/// 加密
/// </summary>
Encode = 1,
/// <summary>
/// 解密
/// </summary>
Decode = 2
}
/// <summary>
/// 文件加密
/// </summary>
/// <param name="strFileName"></param>
/// <param name="operateType">MyClass.OpType.Encode加密,MyClass.OpType.Decode解密</param>
/// <param name="strPassword">密码:最多三个字母</param>
public void ModifyFileHead(string strFileName, OpType operateType, string strPassword)
{
switch (operateType)
{
case OpType.Encode:
{
if (strPassword.Length > 3) { return; }
char[] c = strPassword.ToCharArray();
FileStream fs = new