Пример #1
0
 /// <summary>
 /// protected virtual void WriteFile(string secretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType)
 /// </summary>
 /// <param name="secretKey"></param>
 /// <param name="data"></param>
 /// <param name="version"></param>
 /// <param name="encryptor"></param>
 /// <param name="algType"></param>
 /// <param name="algKeyType"></param>
 protected virtual void WriteFile(string secretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType)
 {
     using (FileStream f = new FileStream(_fileName, FileMode.Create))
     {
         using (BinaryWriter w = new BinaryWriter(f))
         {
             try
             {
                 w.Write((Int16)5);
                 w.Write((byte)version);
                 w.Write(Convert.ToByte((int)algType));
                 w.Write(Convert.ToByte((int)algKeyType));
                 w.Write(encryptor.ObjectCryptography(data, TransformType.ENCRYPT));
                 w.Flush();
             }
             catch (IOException e)
             {
                 throw e;
             }
             finally
             {
                 w.Close();
                 f.Close();
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// public virtual string ObjectCryptography(string secretKey, string data, TransformType type, AlgorithmType algType, AlgorithmKeyType algKeyType)
        /// </summary>
        /// <param name="secretKey"></param>
        /// <param name="data"></param>
        /// <param name="type"></param>
        /// <param name="algType"></param>
        /// <param name="algKeyType"></param>
        /// <returns></returns>
        public virtual string ObjectCryptography(string secretKey, string data, TransformType type, AlgorithmType algType, AlgorithmKeyType algKeyType)
        {
            string value = null;

            switch (algType)
            {
            case AlgorithmType.DES:
                Encryptor = new AlgorithmDES(secretKey, algKeyType);
                value     = Encryptor.ObjectCryptography(data, type);
                break;

            case AlgorithmType.Rijndael:
                Encryptor = new AlgorithmRijndael(secretKey, algKeyType);
                value     = Encryptor.ObjectCryptography(data, type);
                break;

            case AlgorithmType.TripleDES:
                Encryptor = new AlgorithmTripleDES(secretKey, algKeyType);
                value     = Encryptor.ObjectCryptography(data, type);
                break;

            default:
                break;
            }
            return(value);
        }
Пример #3
0
 /// <summary>
 /// protected virtual byte[] WriteMenoryStream(string seretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType)
 /// </summary>
 /// <param name="seretKey"></param>
 /// <param name="data"></param>
 /// <param name="version"></param>
 /// <param name="encryptor"></param>
 /// <param name="algType"></param>
 /// <param name="algKeyType"></param>
 /// <returns></returns>
 protected virtual byte[] WriteMenoryStream(string seretKey, byte[] data, Version version, Encryptor encryptor, AlgorithmType algType, AlgorithmKeyType algKeyType)
 {
     byte[] value = null;
     using (MemoryStream ms = new MemoryStream())
     {
         using (BinaryWriter w = new BinaryWriter(ms))
         {
             try
             {
                 w.Write((Int16)5);
                 w.Write((byte)version);
                 w.Write(Convert.ToByte((int)algType));
                 w.Write(Convert.ToByte((int)algKeyType));
                 w.Write(encryptor.ObjectCryptography(data, TransformType.ENCRYPT));
                 w.Flush();
                 value = ms.ToArray();
             }
             catch (Exception e)
             {
                 throw e;
             }
             finally
             {
                 w.Close();
                 ms.Close();
             }
         }
     }
     return(value);
 }