/// <summary> /// Read a keyblob of the given type from the buffer, and return it as /// a key. Only RSA and DSA keys are supported. /// </summary> /// <param name="type"></param> /// <returns></returns> public Key ReadKeyBlob(string type) { switch (type) { case "ssh-dss": var dsakey = new DsaKey(); dsakey.P = ReadBigNum(); dsakey.Q = ReadBigNum(); dsakey.G = ReadBigNum(); dsakey.X = ReadBigNum(); //pub return dsakey; case "ssh-rsa": var rsakey = new RsaKey(); rsakey.Exponent = ReadBigNum(); rsakey.Modulus = ReadBigNum(); return rsakey; default: throw new NotSupportedException(string.Format("unsupported key type `{0}'", type)); } }
public void WriteRsaKeyShouldWriteArgumentToEndOfBuffer() { var buffer = new Buffer("start"); var key = new RsaKey(); key.Exponent = new BigInteger(new byte[] { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88 }); key.Modulus = new BigInteger(new byte[] { 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 }); buffer.WriteKey(key); Assert.AreEqual( "start\0\0\0\x7ssh-rsa\0\0\0\x8\xff\xee\xdd\xcc\xbb\xaa\x99\x88\0\0\0\x8\x77\x66\x55\x44\x33\x22\x11\x00", buffer.ToString()); }