コード例 #1
0
ファイル: AESCryptor.cs プロジェクト: s455016457/MyDevTools
 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("秘钥初始化失败,秘钥文件被破坏!");
     }
 }
コード例 #2
0
ファイル: ChatHub.cs プロジェクト: claudiu-bruma/sps.signalr
        public async Task SendMessage(string user, string message)
        {
            var aesDecriptedMesage = AesCryptoHelper.DecryptString_Aes(message);

            SaveMessageToLog(user, aesDecriptedMesage);

            await Clients.All.SendAsync("ReceiveMessage", user, aesDecriptedMesage);
        }
コード例 #3
0
 protected virtual byte[] Encryptor(byte[] bytes)
 {
     /**
      * 对数据加密
      * 用密码加密数据
      * 对数据签名
      * */
     bytes = Cryptor.Encryptor(bytes);
     bytes = AesCryptoHelper.Encrypt(bytes, GetKeyBytesByPasword(), null);
     bytes = Sign.Sign(bytes, GetSignBytes());
     return(bytes);
 }
コード例 #4
0
        public async Task <IActionResult> SendMessage([FromBody] Message message)
        {
            connection = new HubConnectionBuilder()
                         .WithUrl(hubUrl)
                         .Build();

            await connection.StartAsync();

            var aesEncriptedMesage = AesCryptoHelper.EncryptString_Aes(message.MessageContent);
            await connection.InvokeAsync("SendMessage", message.User, aesEncriptedMesage);

            return(new OkResult());
        }
コード例 #5
0
        private async void sendButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var aesEncriptedMesage = AesCryptoHelper.EncryptString_Aes(messageTextBox.Text);

                await connection.InvokeAsync("SendMessage", userTextBox.Text, aesEncriptedMesage);
            }
            catch (Exception ex)
            {
                messagesList.Items.Add(ex.Message);
            }
        }
コード例 #6
0
ファイル: EmployeeService.cs プロジェクト: EugeneRymarev/HES
        private string GenerateMasterPassword()
        {
            var buf = AesCryptoHelper.CreateRandomBuf(32);

            for (int i = 0; i < 32; i++)
            {
                if (buf[i] == 0)
                {
                    buf[i] = 0xff;
                }
            }
            var pass = ConvertUtils.ByteArrayToHexString(buf);

            return(pass);
        }
コード例 #7
0
        protected virtual byte[] Decryptor(byte[] bytes)
        {
            /**
             * 验证签名
             * 用密码解密数据
             * 对数据码解
             * */

            if (!Sign.Verify(bytes, GetSignBytes(), out bytes))
            {
                throw new Exception("密文被篡改!");
            }

            try
            {
                bytes = AesCryptoHelper.Decrypt(bytes, GetKeyBytesByPasword(), null);
            }
            catch (Exception ex)
            {
                throw new Exception("密码不正确!", ex.InnerException);
            }
            bytes = Cryptor.Decryptor(bytes);
            return(bytes);
        }
コード例 #8
0
ファイル: AESCryptor.cs プロジェクト: s455016457/MyDevTools
 public byte[] Encryptor(byte[] bytes)
 {
     return(AesCryptoHelper.Encrypt(bytes, Convert.FromBase64String(Key.Key), Convert.FromBase64String(Key.Value)));
 }