private static Common.Output EncryptMessageFromkiosk(string message)
 {
     try
     {
         _db = new PilaDbContext();
         ConnectionInfo profile = _db.ConnectionInfoes.First(c => c.Active == 1);
         if (profile != null)
         {
             var        keyValue  = Encoding.ASCII.GetString(profile.PublicKey);
             KeyManager keyM      = new KeyManager();
             var        encrypted = keyM.EncryptPGP(profile.KeyName, profile.KeyName, profile.KeyPass, message,
                                                    profile.PublicKey);
             if (!string.IsNullOrEmpty(encrypted.Value = "0"))
             {
                 return(new Common.Output("FAILED", "0", DateTime.Now, false, "Encryption Error : " + encrypted.Notes));
             }
             return(new Common.Output("SUCCESS", "1", DateTime.Now, true, encrypted.Notes));
         }
         return(new Common.Output("HALTED", "0", DateTime.Now, false, "PROFILING ERROR "));
     }
     catch (Exception ex)
     {
         return(new Common.Output("FAILED", "0", DateTime.Now, false, "Encryption Error : " + ex.Message));
     }
 }
 private static Common.Output DecryptMessageFromTms(string notes)
 {
     try
     {
         _db = new PilaDbContext();
         ConnectionInfo profile   = _db.ConnectionInfoes.First(c => c.Active == 1);
         var            keyData   = profile.PrivateKey;
         KeyManager     keyM      = new KeyManager();
         var            decrypted = keyM.DecryptPGP(profile.KeyName, profile.KeyName, profile.KeyPass, notes, keyData);
         if (decrypted.Value == "0")
         {
             return(new Common.Output("FAILED", "0", DateTime.Now, false, "Encryption Error : " + decrypted.Notes));
         }
         return(new Common.Output("SUCCESS", "1", DateTime.Now, true, decrypted.Notes));
     }
     catch (Exception ex)
     {
         return(new Common.Output("FAILED", "0", DateTime.Now, false, "Encryption Error : " + ex.Message));
     }
 }
        public static string DoMethod(string messageType, string origin, string destination, string adminuser, string transactionId, string senderIpAdd, int userId, decimal longitud, decimal latitude, string screen, string state, string description, string contentType, string notes, string amount, string accountNo)
        {
            try
            {
                _db = new PilaDbContext();
                ConnectionInfo profInfo = _db.ConnectionInfoes.First(c => c.Active == 1);
                if (profInfo != null)
                {
                    //instantiate Message Headers
                    MessageHeader mHeader = new MessageHeader
                    {
                        MessageType     = messageType,
                        Origin          = GetMacAddress(),
                        Destination     = profInfo.IPAddress + ":" + profInfo.SocketPort,
                        AdminUser       = adminuser,
                        TransactionCode = transactionId
                    };


                    //instantiate Message Trail
                    MessageTrail mTrail = new MessageTrail
                    {
                        IPAddress = senderIpAdd,
                        MAC       = GetMacAddress(),
                        SentDate  = DateTime.Now,
                        UserId    = userId,
                        Latitude  = latitude,
                        Longitude = longitud,
                        Screen    = screen,
                        State     = state
                    };

                    var allContents = new List <Content>();
                    //Add deposit content
                    allContents.Add(TransactionCls.MethodContent);

                    ////Add denomination content
                    //allContents.Add(TransactionCls.DenominationContents);


                    //instantiate Message content
                    MessageContent mContent = new MessageContent
                    {
                        IsEncryted  = true,
                        Description = description,
                        ContentType = contentType,
                        Contents    = allContents
                    };

                    //instantiate PillarSaltMessage content
                    PillarSaltMessage p = new PillarSaltMessage
                    {
                        Notes   = notes,
                        Header  = mHeader,
                        content = mContent,
                        Trails  = mTrail
                    };

                    XmlSerializer x         = new XmlSerializer(p.GetType());
                    var           strWriter = new StringWriter();
                    TextWriter    tw        = new StreamWriter(@"C:\\Machine\\DepositeMessage.xml");

                    x.Serialize(tw, p);
                    x.Serialize(strWriter, p);

                    var             encryptedMessage = EncryptMessageFromkiosk(strWriter.ToString()).Notes;
                    TMSSocketClient sending          = new TMSSocketClient();
                    ConnectionInfo  profile          = _db.ConnectionInfoes.First(c => c.Active == 1);
                    if (profile != null)
                    {
                        var response          = sending.SyncClient(profile.IPAddress, Convert.ToInt32(profile.SocketPort), encryptedMessage);
                        var decryptedResponse = DecryptMessageFromTms(response.Notes);

                        RtnMessage = decryptedResponse.Value;
                        MessageBox.Show(RtnMessage);
                        return(RtnMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                RtnMessage = "ERROR : " + ex.Message;
                MessageBox.Show(RtnMessage);
            }
            return(RtnMessage);
        }