public void SetSecuritySettings(SecuritySettingsInfo securitySettings)
 {
     SecuritySettings = null;
     if (securitySettings.SecurityMode == SecurityMode.None)
     {
         securitySettings.Data = null;
         var result = ConnectorExtension.SendData <SecuritySettingsInfo>(this, new Shared.Models.MethodCallInfo()
         {
             Guid = Guid.NewGuid().ToString(), ServiceName = "/SetSettings", Data = JsonConvert.SerializeObject(securitySettings)
         });
     }
     else if (securitySettings.SecurityMode == SecurityMode.RSA_AESSecurity)
     {
         var keys = RSASecurity.GenerateRandomKey();
         securitySettings.Data = new RSAAESEncryptionData()
         {
             RSAEncryptionKey = keys.PublicKey
         };
         var result = ConnectorExtension.SendData <SecuritySettingsInfo>(this, new Shared.Models.MethodCallInfo()
         {
             Guid = Guid.NewGuid().ToString(), ServiceName = "/SetSettings", Data = JsonConvert.SerializeObject(securitySettings)
         });
         SecuritySettings = new SecuritySettingsInfo()
         {
             Data = new RSAAESEncryptionData()
             {
                 Key = RSASecurity.Decrypt(result.Data.Key, RSASecurity.StringToKey(keys.PrivateKey)), IV = RSASecurity.Decrypt(result.Data.IV, RSASecurity.StringToKey(keys.PrivateKey))
             }, SecurityMode = securitySettings.SecurityMode
         };
     }
 }
Exemplo n.º 2
0
        public async void SetSecuritySettings(SecuritySettingsInfo securitySettings)
#endif
        {
            SecuritySettings = null;
            if (securitySettings.SecurityMode == SecurityMode.None)
            {
                securitySettings.Data = null;
#if (NET40 || NET35)
                SecuritySettingsInfo result = ConnectorExtensions.SendData <SecuritySettingsInfo>(this, new Shared.Models.MethodCallInfo()
                {
                    Guid = Guid.NewGuid().ToString(), ServiceName = "/SetSettings", Data = JsonConvert.SerializeObject(securitySettings)
                });
#else
                SecuritySettingsInfo result = await ConnectorExtensions.SendData <SecuritySettingsInfo>(this, new Shared.Models.MethodCallInfo()
                {
                    Guid = Guid.NewGuid().ToString(), ServiceName = "/SetSettings", Data = JsonConvert.SerializeObject(securitySettings)
                });
#endif
            }
            else if (securitySettings.SecurityMode == SecurityMode.RSA_AESSecurity)
            {
#if (!PORTABLE)
                RSAKey keys = RSASecurity.GenerateRandomKey();
                securitySettings.Data = new RSAAESEncryptionData()
                {
                    RSAEncryptionKey = keys.PublicKey
                };
#if (NET40 || NET35)
                SecuritySettingsInfo result = ConnectorExtensions.SendData <SecuritySettingsInfo>(this, new Shared.Models.MethodCallInfo()
                {
                    Guid = Guid.NewGuid().ToString(), ServiceName = "/SetSettings", Data = JsonConvert.SerializeObject(securitySettings)
                });
#else
                SecuritySettingsInfo result = await ConnectorExtensions.SendData <SecuritySettingsInfo>(this, new Shared.Models.MethodCallInfo()
                {
                    Guid = Guid.NewGuid().ToString(), ServiceName = "/SetSettings", Data = JsonConvert.SerializeObject(securitySettings)
                });
#endif
                SecuritySettings = new SecuritySettingsInfo()
                {
                    Data = new RSAAESEncryptionData()
                    {
                        Key = RSASecurity.Decrypt(result.Data.Key, RSASecurity.StringToKey(keys.PrivateKey)), IV = RSASecurity.Decrypt(result.Data.IV, RSASecurity.StringToKey(keys.PrivateKey))
                    }, SecurityMode = securitySettings.SecurityMode
                };
#endif
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Xử lý RSA
 /// </summary>
 /// <param name="sourceText"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public string ProcessRSA(string sourceText, RSAType type)
 {
     return(type == RSAType.Encrypt ? RSASecurity.Encrypt(sourceText) : RSASecurity.Decrypt(sourceText));
 }