コード例 #1
0
ファイル: ConnectionInfo.cs プロジェクト: luozhiping1987/nfx
        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());
        }
コード例 #2
0
        public byte[] GetPublicKeyBlob()
        {
            SSH2DataWriter w = new SSH2DataWriter();

            w.WriteString(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm));
            _keypair.PublicKey.WriteTo(w);
            return(w.ToByteArray());
        }
コード例 #3
0
ファイル: ConnectionInfo.cs プロジェクト: luozhiping1987/nfx
        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());
        }
コード例 #4
0
        private string FormatBase64EncodedPublicKeyBody()
        {
            SSH2DataWriter wr = new SSH2DataWriter();

            wr.WriteString(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm));
            _keypair.PublicKey.WriteTo(wr);

            return(Encoding.ASCII.GetString(Base64.Encode(wr.ToByteArray())));
        }
コード例 #5
0
        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();
        }