示例#1
0
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            MemoryStream     bOut = new MemoryStream();
            BcpgOutputStream pOut = new BcpgOutputStream(bOut);

            pOut.WriteByte((byte)version);

            if (version == 3 || version == 2)
            {
                pOut.Write(
                    5,                     // the length of the next block
                    (byte)signatureType);

                pOut.WriteInt((int)(creationTime / 1000L));

                pOut.WriteLong(keyId);

                pOut.Write(
                    (byte)keyAlgorithm,
                    (byte)hashAlgorithm);
            }
            else if (version == 4)
            {
                pOut.Write(
                    (byte)signatureType,
                    (byte)keyAlgorithm,
                    (byte)hashAlgorithm);

                EncodeLengthAndData(pOut, GetEncodedSubpackets(hashedData));

                EncodeLengthAndData(pOut, GetEncodedSubpackets(unhashedData));
            }
            else
            {
                throw new IOException("unknown version: " + version);
            }

            pOut.Write(fingerprint);

            if (signature != null)
            {
                pOut.WriteObjects(signature);
            }
            else
            {
                pOut.Write(signatureEncoding);
            }

            bcpgOut.WritePacket(PacketTag.Signature, bOut.ToArray(), true);
        }
示例#2
0
        public virtual byte[] GetEncodedContents()
        {
            MemoryStream     bOut = new MemoryStream();
            BcpgOutputStream pOut = new BcpgOutputStream(bOut);

            pOut.WriteByte((byte)version);
            pOut.WriteInt((int)time);

            if (version <= 3)
            {
                pOut.WriteShort((short)validDays);
            }

            pOut.WriteByte((byte)algorithm);

            pOut.WriteObject((BcpgObject)key);

            return(bOut.ToArray());
        }