public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {
                    pOut.WriteByte((byte)_version);

                    pOut.WriteLong(_keyId);

                    pOut.WriteByte((byte)_algorithm);

                    for (var i = 0; i != _data.Length; i++)
                    {
                        MPInteger.EncodeInteger(pOut, _data[i]);
                    }

                    if (_extraData != null)
                    {
                        if (_extraData.Length > 0xFF)
                        {
                            throw new PgpException("Extra Data is too large.");
                        }
                        pOut.WriteByte((byte)_extraData.Length);
                        pOut.Write(_extraData, 0, _extraData.Length);
                    }

                    bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, bOut.ToArray(), true);
                }
            }
        }
            public override void Encode(IBcpgOutputStream pOut)
            {
                var pk = new SymmetricKeyEncSessionPacket(
                    EncAlgorithm, _s2K, SessionInfo);

                pOut.WritePacket(pk);
            }
Exemplo n.º 3
0
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            bcpgOut.WriteByte((byte)_type);
            bcpgOut.WriteByte((byte)_algorithm);

            if (_type != GnuDummyS2K)
            {
                if (_type != 0)
                {
                    bcpgOut.Write(_iv);
                }

                if (_type == 3)
                {
                    bcpgOut.WriteByte((byte)_itCount);
                }
            }
            else
            {
                bcpgOut.WriteByte((byte)'G');
                bcpgOut.WriteByte((byte)'N');
                bcpgOut.WriteByte((byte)'U');
                bcpgOut.WriteByte((byte)_protectionMode);
            }
        }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     base.Encode(bcpgOut);
     bcpgOut.WriteByte(0x3);
     bcpgOut.WriteByte(this.Reserved);
     bcpgOut.WriteByte((byte)this.HashAlgorithm);
     bcpgOut.WriteByte((byte)this.SymmetricKeyAlgorithm);
 }
        /// <summary>
        /// Encodes the specified BCPG out.
        /// </summary>
        /// <param name="bcpgOut">The BCPG out.</param>
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            var oid = this.Oid.ToBytes();

            bcpgOut.WriteByte((byte)oid.Length);
            bcpgOut.Write(oid, 0, oid.Length);

            var point = new MPInteger(new BigInteger(1, _point.GetEncoded()));

            bcpgOut.WriteObject(point);
        }
Exemplo n.º 6
0
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                for (var i = 0; i != _subpackets.Length; i++)
                {
                    _subpackets[i].Encode(bOut);
                }

                bcpgOut.WritePacket(PacketTag.UserAttribute, bOut.ToArray(), false);
            }
        }
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {

                for (var i = 0; i != _subpackets.Length; i++)
                {
                    _subpackets[i].Encode(bOut);
                }

                bcpgOut.WritePacket(PacketTag.UserAttribute, bOut.ToArray(), false);
            }
        }
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {
                    pOut.WriteByte((byte)_version);

                    switch (_version)
                    {
                    case 2:
                    case 3:
                        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);
                        break;

                    case 4:
                        pOut.Write(
                            (byte)_signatureType,
                            (byte)_keyAlgorithm,
                            (byte)_hashAlgorithm);
                        EncodeLengthAndData(pOut, GetEncodedSubpackets(_hashedData));
                        EncodeLengthAndData(pOut, GetEncodedSubpackets(_unhashedData));
                        break;

                    default:
                        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);
                }
            }
        }
        public override void Encode(
            IBcpgOutputStream bcpgOut)
        {
            using (MemoryStream bOut = new MemoryStream())
            {
                using (BcpgOutputStream pOut = new BcpgOutputStream(bOut))
                {
                    pOut.Write(
                        (byte)version,
                        (byte)sigType,
                        (byte)hashAlgorithm,
                        (byte)keyAlgorithm);

                    pOut.WriteLong(keyId);

                    pOut.WriteByte((byte)nested);

                    bcpgOut.WritePacket(PacketTag.OnePassSignature, bOut.ToArray(), true);
                }
            }
        }
        /// <summary>
        /// Encodes this instance to the given stream.
        /// </summary>
        /// <param name="bcpgOut">The BCPG out.</param>
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {
                    pOut.Write(
                        (byte)Version,
                        (byte)EncAlgorithm);

                    pOut.WriteObject(S2K);

                    if (_secKeyData != null && _secKeyData.Length > 0)
                    {
                        pOut.Write(_secKeyData);
                    }

                    bcpgOut.WritePacket(PacketTag.SymmetricKeyEncryptedSessionKey, bOut.ToArray(), true);
                }
            }
        }
Exemplo n.º 11
0
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     EncodeInteger(bcpgOut, _val);
 }
 public abstract void Encode(IBcpgOutputStream bcpgOut);
Exemplo n.º 13
0
 internal static void EncodeInteger(IBcpgOutputStream bcpgOut, IBigInteger val)
 {
     bcpgOut.WriteShort((short)val.BitLength);
     bcpgOut.Write(val.ToByteArrayUnsigned());
 }
Exemplo n.º 14
0
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteObjects(_d, _p, _q, _u);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.UserId, _idData, true);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteObject(_x);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(_tag, _contents, true);
 }
 public override void Encode(
     IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.Marker, marker, true);
 }
Exemplo n.º 19
0
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.Trust, _levelAndTrustAmount, true);
 }
Exemplo n.º 20
0
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteObject(_x);
 }
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {

                    pOut.WriteByte((byte)_version);

                    switch (_version)
                    {
                        case 2:
                        case 3:
                            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);
                            break;
                        case 4:
                            pOut.Write(
                                (byte)_signatureType,
                                (byte)_keyAlgorithm,
                                (byte)_hashAlgorithm);
                            EncodeLengthAndData(pOut, GetEncodedSubpackets(_hashedData));
                            EncodeLengthAndData(pOut, GetEncodedSubpackets(_unhashedData));
                            break;
                        default:
                            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);
                }
            }
        }
Exemplo n.º 22
0
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            bcpgOut.WriteByte((byte) _type);
            bcpgOut.WriteByte((byte) _algorithm);

            if (_type != GnuDummyS2K)
            {
                if (_type != 0)
                {
                    bcpgOut.Write(_iv);
                }

                if (_type == 3)
                {
                    bcpgOut.WriteByte((byte) _itCount);
                }
            }
            else
            {
                bcpgOut.WriteByte((byte) 'G');
                bcpgOut.WriteByte((byte) 'N');
                bcpgOut.WriteByte((byte) 'U');
                bcpgOut.WriteByte((byte) _protectionMode);
            }
        }
        public override void Encode(
	        IBcpgOutputStream bcpgOut)
        {
            using (MemoryStream bOut = new MemoryStream())
            {
                using (BcpgOutputStream pOut = new BcpgOutputStream(bOut))
                {

                    pOut.Write(
                        (byte) version,
                        (byte) sigType,
                        (byte) hashAlgorithm,
                        (byte) keyAlgorithm);

                    pOut.WriteLong(keyId);

                    pOut.WriteByte((byte) nested);

                    bcpgOut.WritePacket(PacketTag.OnePassSignature, bOut.ToArray(), true);
                }
            }
        }
Exemplo n.º 24
0
 public override void Encode(
     IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.ModificationDetectionCode, digest, false);
 }
            public override void Encode(IBcpgOutputStream pOut)
            {
                var pk = new SymmetricKeyEncSessionPacket(
                    EncAlgorithm, _s2K, SessionInfo);

                pOut.WritePacket(pk);
            }
Exemplo n.º 26
0
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     EncodeInteger(bcpgOut, _val);
 }
 public override void Encode(IBcpgOutputStream pOut)
 {
     var pk = new PublicKeyEncSessionPacket(_pubKey.KeyId, _pubKey.Algorithm, _data, _extraData);
     pOut.WritePacket(pk);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.Trust, _levelAndTrustAmount, true);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteObjects(_d, _p, _q, _u);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.PublicSubkey, GetEncodedContents(), true);
 }
        /// <summary>
        /// Encodes this instance to the given stream.
        /// </summary>
        /// <param name="bcpgOut">The BCPG out.</param>
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {

                    pOut.Write(
                        (byte)Version,
                        (byte)EncAlgorithm);

                    pOut.WriteObject(S2K);

                    if (_secKeyData != null && _secKeyData.Length > 0)
                    {
                        pOut.Write(_secKeyData);
                    }

                    bcpgOut.WritePacket(PacketTag.SymmetricKeyEncryptedSessionKey, bOut.ToArray(), true);
                }
            }
        }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteObjects(_p, _g, _y);
 }
 public override void Encode(
     IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.ModificationDetectionCode, digest, false);
 }
Exemplo n.º 34
0
 internal static void EncodeInteger(IBcpgOutputStream bcpgOut, IBigInteger val)
 {
     bcpgOut.WriteShort((short)val.BitLength);
     bcpgOut.Write(val.ToByteArrayUnsigned());
 }
        /// <summary>
        /// Encodes the specified BCPG out.
        /// </summary>
        /// <param name="bcpgOut">The BCPG out.</param>
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            var oid = this.Oid.ToBytes();
            bcpgOut.WriteByte((byte)oid.Length);
            bcpgOut.Write(oid, 0, oid.Length);

            var point = new MPInteger(new BigInteger(1, _point.GetEncoded()));
            bcpgOut.WriteObject(point);
        }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteObjects(_p, _g, _y);
 }
Exemplo n.º 37
0
 public override void Encode(
     IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.Marker, marker, true);
 }
        public override void Encode(IBcpgOutputStream bcpgOut)
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {

                    pOut.WriteByte((byte)_version);

                    pOut.WriteLong(_keyId);

                    pOut.WriteByte((byte)_algorithm);

                    for (var i = 0; i != _data.Length; i++)
                    {
                        MPInteger.EncodeInteger(pOut, _data[i]);
                    }

                    if (_extraData != null)
                    {
                        if (_extraData.Length > 0xFF)
                            throw new PgpException("Extra Data is too large.");
                        pOut.WriteByte((byte)_extraData.Length);
                        pOut.Write(_extraData, 0, _extraData.Length);
                    }

                    bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, bOut.ToArray(), true);
                }
            }
        }
Exemplo n.º 39
0
 /// <summary>
 /// Encodes this instance to the given stream.
 /// </summary>
 /// <param name="bcpgOut">The BCPG out.</param>
 public abstract void Encode(IBcpgOutputStream bcpgOut);
            public override void Encode(IBcpgOutputStream pOut)
            {
                var pk = new PublicKeyEncSessionPacket(_pubKey.KeyId, _pubKey.Algorithm, _data, _extraData);

                pOut.WritePacket(pk);
            }
 /// <summary>
 /// Encodes this instance to the given stream.
 /// </summary>
 /// <param name="bcpgOut">The BCPG out.</param>
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.SecretSubkey, GetEncodedContents(), true);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(_tag, _contents, true);
 }
Exemplo n.º 43
0
 /// <summary>
 /// Encodes this instance to the given stream.
 /// </summary>
 /// <param name="bcpgOut">The BCPG out.</param>
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.SecretKey, this.GetEncodedContents(), true);
 }
Exemplo n.º 44
0
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     bcpgOut.WritePacket(PacketTag.UserId, _idData, true);
 }
 public override void Encode(IBcpgOutputStream bcpgOut)
 {
     base.Encode(bcpgOut);
     bcpgOut.WriteByte(0x3);
     bcpgOut.WriteByte(this.Reserved);
     bcpgOut.WriteByte((byte)this.HashAlgorithm);
     bcpgOut.WriteByte((byte)this.SymmetricKeyAlgorithm);
 }