Пример #1
0
        public PaswordProjectDataStor GetPaswordProjectDataStor(String password)
        {
            if (dataStor != null)
            {
                return(dataStor);
            }
            dataStor = new PaswordProjectDataStor();
            dataStor.UpdatePassword(password);

            /**
             * 从文件中获取数据
             * 对数据解密
             * 对数据反序列化
             * */
            String message = FileReadWrite.Read();

            if (message == null || message.Length <= 0)
            {
                return(dataStor);
            }

            var bytes = Decryptor(Convert.FromBase64String(message));

            message  = Encoding.UTF8.GetString(bytes);
            dataStor = SerializationHelper.Deserialization(message);

            if (dataStor == null)
            {
                dataStor = new PaswordProjectDataStor();
            }

            return(dataStor);
        }
Пример #2
0
 private void initKey()
 {
     try
     {
         /**
          * 获取秘钥
          * 没有秘钥则产生一对秘钥,并用非明文方式保存秘钥
          * */
         String strKey = FileReadWrite.Read();
         if (String.IsNullOrEmpty(strKey))
         {
             Key    = AesCryptoHelper.CreateKeyAndIv();
             strKey = SerializationHelper.Serialization(Key);
             strKey = AesCryptoHelper.Encrypt(strKey, keyEncryptorKey);
             FileReadWrite.Write(strKey);
         }
         else
         {
             strKey = AesCryptoHelper.Decrypt(strKey, keyEncryptorKey);
             Key    = SerializationHelper.Deserialization(strKey);
         }
     }
     catch (Exception ex)
     {
         var entity = LogEntityFactory.Create(String.Format("秘钥初始化失败:{0}", ex.ToString()),
                                              LogTypeFacotry.CreateExceptionLogType(),
                                              LogLevelFactory.CreateGravenessLogLevel());
         log.SaveLog(entity);
         throw new Exception("秘钥初始化失败,秘钥文件被破坏!");
     }
 }