Пример #1
0
            /// <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(_hostKey.Algorithm.GetAlgorithmName())
                           .Append(' ')
                           .Append(Encoding.ASCII.GetString(Base64.Encode(_encodedHostKey.Value)))
                           .ToString());
                },
                        false
                        );

                _encodedHostKey =
                    new Lazy <byte[]>(
                        () => {
                    SSH2PayloadImageBuilder image = new SSH2PayloadImageBuilder(0x10000);
                    image.WriteString(_hostKey.Algorithm.GetAlgorithmName());
                    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 if (_hostKey is ECDSAPublicKey)
                    {
                        ECDSAPublicKey ec = (ECDSAPublicKey)_hostKey;
                        image.WriteString(ec.CurveName);
                        image.WriteAsString(ec.ToOctetString());
                    }
                    else if (_hostKey is EDDSAPublicKey)
                    {
                        EDDSAPublicKey ed = (EDDSAPublicKey)_hostKey;
                        image.WriteAsString(ed.Bytes);
                    }
                    else
                    {
                        throw new SSHException("Host key algorithm is unsupported");
                    }
                    return(image.GetBytes());
                },
                        false
                        );
            }
Пример #2
0
        public byte[] GetPublicKeyBlob()
        {
            SSH2PayloadImageBuilder imageBuilder =
                new SSH2PayloadImageBuilder()
                .WriteString(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm));

            _keypair.PublicKey.WriteTo(new SSH2KeyWriter(imageBuilder));
            return(imageBuilder.GetBytes());
        }