コード例 #1
0
        public string DumpHostKeyInKnownHostsStyle()
        {
            StringBuilder bld = new StringBuilder();

            bld.Append(SSH2Util.PublicKeyAlgorithmName(_hostkey.Algorithm));
            bld.Append(' ');
            SSH2DataWriter wr = new SSH2DataWriter();

            wr.Write(SSH2Util.PublicKeyAlgorithmName(_hostkey.Algorithm));
            if (_hostkey.Algorithm == PublicKeyAlgorithm.RSA)
            {
                RSAPublicKey rsa = (RSAPublicKey)_hostkey;
                wr.Write(rsa.Exponent);
                wr.Write(rsa.Modulus);
            }
            else if (_hostkey.Algorithm == PublicKeyAlgorithm.DSA)
            {
                DSAPublicKey dsa = (DSAPublicKey)_hostkey;
                wr.Write(dsa.P);
                wr.Write(dsa.Q);
                wr.Write(dsa.G);
                wr.Write(dsa.Y);
            }
            else
            {
                //throw new Exception("Host key algorithm is unsupported");
                throw new Exception("Host key algorithm is unsupported");
            }

            byte[] tmpdata = Base64.Encode(wr.ToByteArray());
            bld.Append(Encoding.UTF8.GetString(tmpdata, 0, tmpdata.Length));
            return(bld.ToString());
        }
コード例 #2
0
        public byte[] GetPublicKeyBlob()
        {
            SSH2DataWriter w = new SSH2DataWriter();

            w.Write(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm));
            _keypair.PublicKey.WriteTo(w);
            return(w.ToByteArray());
        }
コード例 #3
0
        private string FormatBase64EncodedPublicKeyBody()
        {
            SSH2DataWriter wr = new SSH2DataWriter();

            wr.Write(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm));
            _keypair.PublicKey.WriteTo(wr);
            byte[] tmpdata = Base64.Encode(wr.ToByteArray());
            return(Encoding.UTF8.GetString(tmpdata, 0, tmpdata.Length));
        }
コード例 #4
0
        internal void WritePublicPartInOpenSSHStyle(Stream dest)
        {
            StreamWriter sw = new StreamWriter(dest, Encoding.UTF8);

            sw.Write(SSH2Util.PublicKeyAlgorithmName(_keypair.Algorithm));
            sw.Write(' ');
            sw.WriteLine(FormatBase64EncodedPublicKeyBody());
            sw.Dispose();
        }