/// <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 WriteDssKeyShouldWriteArgumentToEndOfBuffer() { var buffer = new Buffer("start"); var key = new DsaKey(); key.P = new BigInteger(new byte[] {0x0, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88}); key.Q = new BigInteger(new byte[] {0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}); key.G = new BigInteger(new byte[] {0, 0xff, 0xdd, 0xbb, 0x99, 0x77, 0x55, 0x33, 0x11}); key.X = new BigInteger(new byte[] {0xee, 0xcc, 0xaa, 0x88, 0x66, 0x44, 0x22, 0x00}); buffer.WriteKey(key); Assert.AreEqual( "start\0\0\0\x7ssh-dss\0\0\0\x8\xff\xee\xdd\xcc\xbb\xaa\x99\x88\0\0\0\x8\x77\x66\x55\x44\x33\x22\x11\x00\0\0\0\x8\xff\xdd\xbb\x99\x77\x55\x33\x11\0\0\0\x8\xee\xcc\xaa\x88\x66\x44\x22\x00", buffer.ToString()); }