public clsSFTP() { #if (DEBUG) m_rec_sftp = (from s in Program.dbData3060.Tblsftp where s.Navn == "TestHD35" select s).First(); //m_rec_sftp = (from s in Program.dbData3060.Tblsftp where s.Navn == "Test" select s).First(); //m_rec_sftp = (from s in Program.dbData3060.Tblsftp where s.Navn == "Produktion" select s).First(); #else m_rec_sftp = (from s in Program.dbData3060.Tblsftp where s.Navn == "Produktion" select s).First(); #endif m_sftp = new SFtp(); bool success = m_sftp.UnlockComponent("HAFSJOSSH_6pspJCMP1QnW"); if (!success) { throw new Exception(m_sftp.LastErrorText); } m_sftp.ConnectTimeoutMs = 5000; m_sftp.IdleTimeoutMs = 15000; success = m_sftp.Connect(m_rec_sftp.Host, int.Parse(m_rec_sftp.Port)); if (!success) { throw new Exception(m_sftp.LastErrorText); } Chilkat.SshKey key = new Chilkat.SshKey(); string privKey = m_rec_sftp.Certificate; if (privKey == null) { throw new Exception(m_sftp.LastErrorText); } key.Password = m_rec_sftp.Pincode; success = key.FromOpenSshPrivateKey(privKey); if (!success) { throw new Exception(m_sftp.LastErrorText); } success = m_sftp.AuthenticatePk(m_rec_sftp.User, key); if (!success) { throw new Exception(m_sftp.LastErrorText); } // After authenticating, the SFTP subsystem must be initialized: success = m_sftp.InitializeSftp(); if (!success) { throw new Exception(m_sftp.LastErrorText); } }
static async System.Threading.Tasks.Task Main(string[] args) { Console.WriteLine("Hello World!"); Chilkat.SshKey key = new Chilkat.SshKey(); int numbits = 2048; int exponent = 65537; bool success = key.GenerateRsaKey(numbits, exponent); if (!success) { Console.WriteLine("Failed"); } Console.WriteLine("Generating Private Key"); Console.WriteLine(key.ToOpenSshPrivateKey(false)); Console.WriteLine("Generating Public SSH KEY-1"); Console.WriteLine(key.ToOpenSshPublicKey()); Console.WriteLine("Generating Public SSH KEY-2"); Console.WriteLine(key.ToOpenSshPublicKey()); // Store the value in Consul KV using (var client = new ConsulClient()) { var putPair = new KVPair("secretkey") { Value = Encoding.UTF8.GetBytes(key.ToOpenSshPublicKey()) }; var putAttempt = await client.KV.Put(putPair); if (putAttempt.Response) { var getPair = await client.KV.Get("secretkey1"); if (String.IsNullOrEmpty(getPair.Response)) { Console.WriteLine("Getting Back the Stored String"); Console.WriteLine(Encoding.UTF8.GetString(getPair.Response.Value, 0, getPair.Response.Value.Length)); } } } }
public clsSFTP() { clsRest objRest = new clsRest(); string strxmldata = objRest.HttpGet2(clsRest.urlBaseType.data, "sftp/" + Program.sftpName); XDocument xdoc = XDocument.Parse(strxmldata); string Status = xdoc.Descendants("Status").First().Value; if (Status != "True") { throw new Exception("Getting sftp-data for " + Program.sftpName + " failed."); } m_SftpId = xdoc.Descendants("Id").First().Value; m_SftpNavn = xdoc.Descendants("Navn").First().Value; m_Host = xdoc.Descendants("Host").First().Value; m_Port = xdoc.Descendants("Port").First().Value; m_Certificate = xdoc.Descendants("Certificate").First().Value; m_Pincode = xdoc.Descendants("Pincode").First().Value; m_User = xdoc.Descendants("User").First().Value; m_Outbound = xdoc.Descendants("Outbound").First().Value; m_Inbound = xdoc.Descendants("Inbound").First().Value; m_sftp = new SFtp(); bool success = m_sftp.UnlockComponent("HAFSJOSSH_6pspJCMP1QnW"); if (!success) { throw new Exception(m_sftp.LastErrorText); } m_sftp.ConnectTimeoutMs = 60000; m_sftp.IdleTimeoutMs = 55000; success = m_sftp.Connect(m_Host, int.Parse(m_Port)); if (!success) { throw new Exception(m_sftp.LastErrorText); } Chilkat.SshKey key = new Chilkat.SshKey(); string privKey = m_Certificate; if (privKey == null) { throw new Exception(m_sftp.LastErrorText); } key.Password = m_Pincode; success = key.FromOpenSshPrivateKey(privKey); if (!success) { throw new Exception(m_sftp.LastErrorText); } success = m_sftp.AuthenticatePk(m_User, key); if (!success) { throw new Exception(m_sftp.LastErrorText); } // After authenticating, the SFTP subsystem must be initialized: success = m_sftp.InitializeSftp(); if (!success) { throw new Exception(m_sftp.LastErrorText); } }