private byte[] WriteToDataWriter() { SSH2DataWriter wr = new SSH2DataWriter(); wr.WriteString(SSH2Util.PublicKeyAlgorithmName(_hostkey.Algorithm)); if (_hostkey.Algorithm == PublicKeyAlgorithm.RSA) { RSAPublicKey rsa = (RSAPublicKey)_hostkey; wr.WriteBigInteger(rsa.Exponent); wr.WriteBigInteger(rsa.Modulus); } else if (_hostkey.Algorithm == PublicKeyAlgorithm.DSA) { DSAPublicKey dsa = (DSAPublicKey)_hostkey; wr.WriteBigInteger(dsa.P); wr.WriteBigInteger(dsa.Q); wr.WriteBigInteger(dsa.G); wr.WriteBigInteger(dsa.Y); } else { throw new SSHException("Host key algorithm is unsupported"); } return(wr.ToByteArray()); }
public byte[] GetPublicKeyBlob() { SSH2DataWriter w = new SSH2DataWriter(); w.Write(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm)); _keypair.PublicKey.WriteTo(w); return(w.ToByteArray()); }
public byte[] GetPublicKeyBlob() { SSH2PayloadImageBuilder imageBuilder = new SSH2PayloadImageBuilder() .WriteString(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm)); _keypair.PublicKey.WriteTo(new SSH2KeyWriter(imageBuilder)); return(imageBuilder.GetBytes()); }
public void WritePublicPartInOpenSSHStyle(Stream dest) { StreamWriter sw = new StreamWriter(dest, Encoding.ASCII); sw.Write(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm)); sw.Write(' '); sw.WriteLine(FormatBase64EncodedPublicKeyBody()); sw.Close(); }
public override string DumpHostKeyInKnownHostsStyle() { StringBuilder bld = new StringBuilder(); bld.Append(SSH2Util.PublicKeyAlgorithmName(_hostkey.Algorithm)); bld.Append(' '); bld.Append(Encoding.ASCII.GetString(Base64.Encode(WriteToDataWriter()))); return(bld.ToString()); }
private string FormatBase64EncodedPublicKeyBody() { SSH2DataWriter wr = new SSH2DataWriter(); wr.Write(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm)); _keypair.PublicKey.WriteTo(wr); return(Encoding.ASCII.GetString(Base64.Encode(wr.ToByteArray()))); }
/// <summary> /// Constructor /// </summary> /// <param name="hostName">host name</param> /// <param name="portNumber">port number</param> /// <param name="hostKey">host key</param> public SSH2HostKeyInformationProvider(string hostName, int portNumber, PublicKey hostKey) { HostName = hostName; PortNumber = portNumber; _hostKey = hostKey; _knownHostsString = new Lazy <string>( () => { // Poderosa known_hosts format return(new StringBuilder() .Append(SSH2Util.PublicKeyAlgorithmName(_hostKey.Algorithm)) .Append(' ') .Append(Encoding.ASCII.GetString(Base64.Encode(_encodedHostKey.Value))) .ToString()); }, false ); _encodedHostKey = new Lazy <byte[]>( () => { SSH2PayloadImageBuilder image = new SSH2PayloadImageBuilder(0x10000); image.WriteString(SSH2Util.PublicKeyAlgorithmName(_hostKey.Algorithm)); if (_hostKey is RSAPublicKey) { RSAPublicKey rsa = (RSAPublicKey)_hostKey; image.WriteBigInteger(rsa.Exponent); image.WriteBigInteger(rsa.Modulus); } else if (_hostKey is DSAPublicKey) { DSAPublicKey dsa = (DSAPublicKey)_hostKey; image.WriteBigInteger(dsa.P); image.WriteBigInteger(dsa.Q); image.WriteBigInteger(dsa.G); image.WriteBigInteger(dsa.Y); } else { throw new SSHException("Host key algorithm is unsupported"); } return(image.GetBytes()); }, false ); }