Beispiel #1
0
    public override void Encode(BcpgOutputStream bcpgOut)
    {
        MemoryStream     memoryStream     = new MemoryStream();
        BcpgOutputStream bcpgOutputStream = new BcpgOutputStream(memoryStream);

        bcpgOutputStream.WriteByte((byte)version);
        if (version == 3 || version == 2)
        {
            bcpgOutputStream.Write(5, (byte)signatureType);
            bcpgOutputStream.WriteInt((int)(creationTime / 1000));
            bcpgOutputStream.WriteLong(keyId);
            bcpgOutputStream.Write((byte)keyAlgorithm, (byte)hashAlgorithm);
        }
        else
        {
            if (version != 4)
            {
                throw new IOException("unknown version: " + version);
            }
            bcpgOutputStream.Write((byte)signatureType, (byte)keyAlgorithm, (byte)hashAlgorithm);
            EncodeLengthAndData(bcpgOutputStream, GetEncodedSubpackets(hashedData));
            EncodeLengthAndData(bcpgOutputStream, GetEncodedSubpackets(unhashedData));
        }
        bcpgOutputStream.Write(fingerprint);
        if (signature != null)
        {
            bcpgOutputStream.WriteObjects(signature);
        }
        else
        {
            bcpgOutputStream.Write(signatureEncoding);
        }
        bcpgOut.WritePacket(PacketTag.Signature, memoryStream.ToArray(), oldFormat: true);
    }
Beispiel #2
0
    public virtual byte[] GetEncodedContents()
    {
        MemoryStream     memoryStream     = new MemoryStream();
        BcpgOutputStream bcpgOutputStream = new BcpgOutputStream(memoryStream);

        bcpgOutputStream.WriteByte((byte)version);
        bcpgOutputStream.WriteInt((int)time);
        if (version <= 3)
        {
            bcpgOutputStream.WriteShort((short)validDays);
        }
        bcpgOutputStream.WriteByte((byte)algorithm);
        bcpgOutputStream.WriteObject((BcpgObject)key);
        return(memoryStream.ToArray());
    }