Example #1
0
        public Certificate(ByteBuffer payload, AsymmetricKey publicKey, AsymmetricKey theCAPrivateKey)
        {
            PIsValid          = false;
            SignatureByteSize = 0;

            if (payload.GetBufferSize() > MaxPayloadSize || !publicKey.IsValid())
            {
                return;
            }

            var thePublicKey = PublicKey.GetPublicKey();
            var packet       = new PacketStream();

            packet.Write(payload);
            packet.Write(thePublicKey);

            SignatureByteSize = packet.GetBytePosition();
            packet.SetBytePosition(SignatureByteSize);

            var theSignedBytes = new ByteBuffer(packet.GetBuffer(), packet.GetBytePosition());

            Signature = theCAPrivateKey.HashAndSign(theSignedBytes);
            packet.Write(Signature);

            SetBuffer(packet.GetBuffer(), packet.GetBytePosition());
        }
Example #2
0
        public void Parse()
        {
            var aStream = new BitStream(GetBuffer(), GetBufferSize());

            PayLoad = new ByteBuffer(0U);
            aStream.Read(PayLoad);

            PublicKey = new AsymmetricKey(aStream);
            Signature = new ByteBuffer(0U);

            SignatureByteSize = aStream.GetBytePosition();

            aStream.SetBytePosition(SignatureByteSize);

            aStream.Read(Signature);

            if (aStream.IsValid() && GetBufferSize() == aStream.GetBytePosition() && PublicKey.IsValid())
            {
                PIsValid = true;
            }
        }