Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Key"/> class.
        /// </summary>
        /// <param name="data">DER encoded private key data.</param>
        public Key(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            var der     = new DerData(data);
            var version = der.ReadBigInteger();

            var keys = new List <BigInteger>();

            while (!der.IsEndOfData)
            {
                keys.Add(der.ReadBigInteger());
            }

            this._privateKey = keys.ToArray();
        }
Beispiel #2
0
        public void ReadBigIntegerTest()
        {
            DerData    target   = new DerData();    // TODO: Initialize to an appropriate value
            BigInteger expected = new BigInteger(); // TODO: Initialize to an appropriate value
            BigInteger actual;

            actual = target.ReadBigInteger();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Key"/> class.
        /// </summary>
        /// <param name="data">DER encoded private key data.</param>
        protected Key(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            var der = new DerData(data);

            der.ReadBigInteger(); // skip version

            var keys = new List <BigInteger>();

            while (!der.IsEndOfData)
            {
                keys.Add(der.ReadBigInteger());
            }

            _privateKey = keys.ToArray();
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EcdsaKey"/> class.
        /// </summary>
        /// <param name="data">DER encoded private key data.</param>
        public EcdsaKey(byte[] data)
        {
            var der     = new DerData(data);
            var version = der.ReadBigInteger(); // skip version

            // PrivateKey
            var privatekey = der.ReadOctetString().TrimLeadingZeros();

            // Construct
            var s0 = der.ReadByte();

            if ((s0 & 0xe0) != 0xa0)
            {
                throw new SshException(string.Format("UnexpectedDER: wanted constructed tag (0xa0-0xbf), got: {0:X}", s0));
            }
            var tag = s0 & 0x1f;

            if (tag != 0)
            {
                throw new SshException(string.Format("expected tag 0 in DER privkey, got: {0}", tag));
            }
            var construct = der.ReadBytes(der.ReadLength()); // object length

            // curve OID
            var curve_der = new DerData(construct, true);
            var curve     = curve_der.ReadObject();

            // Construct
            s0 = der.ReadByte();
            if ((s0 & 0xe0) != 0xa0)
            {
                throw new SshException(string.Format("UnexpectedDER: wanted constructed tag (0xa0-0xbf), got: {0:X}", s0));
            }
            tag = s0 & 0x1f;
            if (tag != 1)
            {
                throw new SshException(string.Format("expected tag 1 in DER privkey, got: {0}", tag));
            }
            construct = der.ReadBytes(der.ReadLength()); // object length

            // PublicKey
            var pubkey_der = new DerData(construct, true);
            var pubkey     = pubkey_der.ReadBitString().TrimLeadingZeros();

            Import(OidByteArrayToString(curve), pubkey, privatekey);
        }