Write() public méthode

public Write ( byte buffer, int offset, int count ) : void
buffer byte
offset int
count int
Résultat void
Exemple #1
0
        /// <summary>
        /// Gets the encoded contents.
        /// </summary>
        /// <returns></returns>
        public byte[] GetEncodedContents()
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {
                    pOut.Write(PublicKeyPacket.GetEncodedContents());
                    pOut.WriteByte((byte)this.S2KUsage);

                    if (this.S2KUsage == UsageChecksum || this.S2KUsage == UsageSha1)
                    {
                        pOut.WriteByte((byte)this.EncAlgorithm);
                        pOut.WriteObject(this.S2K);
                    }

                    if (_iv != null)
                    {
                        pOut.Write(_iv);
                    }

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

                    return(bOut.ToArray());
                }
            }
        }
Exemple #2
0
        public byte[] GetEncodedContents()
        {
            MemoryStream     bOut = new MemoryStream();
            BcpgOutputStream pOut = new BcpgOutputStream(bOut);

            pOut.Write(pubKeyPacket.GetEncodedContents());

            pOut.WriteByte((byte)s2kUsage);

            if (s2kUsage == UsageChecksum || s2kUsage == UsageSha1)
            {
                pOut.WriteByte((byte)encAlgorithm);
                pOut.WriteObject(s2k);
            }

            if (iv != null)
            {
                pOut.Write(iv);
            }

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

            return(bOut.ToArray());
        }
        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);
        }
        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);
                }
            }
        }
Exemple #5
0
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            MemoryStream     val = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream((Stream)(object)val);

            bcpgOutputStream.Write((byte)version, (byte)encAlgorithm);
            bcpgOutputStream.WriteObject(s2k);
            if (secKeyData != null && secKeyData.Length > 0)
            {
                bcpgOutputStream.Write(secKeyData);
            }
            bcpgOut.WritePacket(PacketTag.SymmetricKeyEncryptedSessionKey, val.ToArray(), oldFormat: true);
        }
Exemple #6
0
 private static void EncodeLengthAndData(
     BcpgOutputStream pOut,
     byte[]                          data)
 {
     pOut.WriteShort((short)data.Length);
     pOut.Write(data);
 }
        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(
            BcpgOutputStream 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);
            }
        }
		internal static void Encode(
			BcpgOutputStream	bcpgOut,
			BigInteger			val)
		{
			bcpgOut.WriteShort((short) val.BitLength);
			bcpgOut.Write(val.ToByteArrayUnsigned());
		}
Exemple #10
0
 internal static void Encode(
     BcpgOutputStream bcpgOut,
     BigInteger val)
 {
     bcpgOut.WriteShort((short)val.BitLength);
     bcpgOut.Write(val.ToByteArrayUnsigned());
 }
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            MemoryStream     memoryStream     = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream(memoryStream);

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

            bcpgOutputStream.Write(new byte[]
            {
                (byte)this.version,
                (byte)this.encAlgorithm
            });
            bcpgOutputStream.WriteObject(this.s2k);
            if (this.secKeyData != null && this.secKeyData.Length > 0)
            {
                bcpgOutputStream.Write(this.secKeyData);
            }
            bcpgOut.WritePacket(PacketTag.SymmetricKeyEncryptedSessionKey, memoryStream.ToArray(), true);
        }
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            byte[] oid = this.oid.GetEncoded();
            bcpgOut.Write(oid, 1, oid.Length - 1);

            MPInteger point = new MPInteger(this.point);
            bcpgOut.WriteObject(point);
        }
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            int length = val.BitLength;

            bcpgOut.WriteByte((byte)(length >> 8));
            bcpgOut.WriteByte((byte)length);

            byte[] bytes = val.ToByteArray();

            if (bytes[0] == 0)
            {
                bcpgOut.Write(bytes, 1, bytes.Length - 1);
            }
            else
            {
                bcpgOut.Write(bytes);
            }
        }
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            MemoryStream bOut = new MemoryStream();
            BcpgOutputStream 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);
        }
Exemple #16
0
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            int length = val.BitLength;

            bcpgOut.WriteByte((byte) (length >> 8));
            bcpgOut.WriteByte((byte) length);

            byte[] bytes = val.ToByteArray();

            if (bytes[0] == 0)
            {
                bcpgOut.Write(bytes, 1, bytes.Length - 1);
            }
            else
            {
                bcpgOut.Write(bytes);
            }
        }
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            MemoryStream     bOut = new MemoryStream();
            BcpgOutputStream 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);
        }
Exemple #18
0
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            byte[] oid = this.oid.GetEncoded();
            bcpgOut.Write(oid, 1, oid.Length - 1);

            MPInteger point = new MPInteger(this.point);

            bcpgOut.WriteObject(point);
        }
        /// <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);
                }
            }
        }
Exemple #20
0
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            MemoryStream     val = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream((Stream)(object)val);

            bcpgOutputStream.Write((byte)version, (byte)sigType, (byte)hashAlgorithm, (byte)keyAlgorithm);
            bcpgOutputStream.WriteLong(keyId);
            ((Stream)bcpgOutputStream).WriteByte((byte)nested);
            bcpgOut.WritePacket(PacketTag.OnePassSignature, val.ToArray(), oldFormat: true);
        }
        public byte[] GetEncodedContents()
        {
            MemoryStream     memoryStream     = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream(memoryStream);

            bcpgOutputStream.Write(this.pubKeyPacket.GetEncodedContents());
            bcpgOutputStream.WriteByte((byte)this.s2kUsage);
            if (this.s2kUsage == 255 || this.s2kUsage == 254)
            {
                bcpgOutputStream.WriteByte((byte)this.encAlgorithm);
                bcpgOutputStream.WriteObject(this.s2k);
            }
            if (this.iv != null)
            {
                bcpgOutputStream.Write(this.iv);
            }
            if (this.secKeyData != null && this.secKeyData.Length > 0)
            {
                bcpgOutputStream.Write(this.secKeyData);
            }
            return(memoryStream.ToArray());
        }
        public static void SignFile(Stream input, Stream outputStream, Stream keyIn, char[] pass)
        {
            var secretKey = ReadSecretKey(keyIn);
            var privateKey = secretKey.ExtractPrivateKey(pass);

            var signatureGenerator = new PgpSignatureGenerator(secretKey.PublicKey.Algorithm, HashAlgorithmTag.Sha1);
            var subpacketGenerator = new PgpSignatureSubpacketGenerator();

            signatureGenerator.InitSign(PgpSignature.CanonicalTextDocument, privateKey);
            foreach (string userId in secretKey.PublicKey.GetUserIds())
            {
                var signatureSubpacketGenerator = new PgpSignatureSubpacketGenerator();
                signatureSubpacketGenerator.SetSignerUserId(isCritical: false, userId: userId);
                signatureGenerator.SetHashedSubpackets(signatureSubpacketGenerator.Generate());
                // Just the first one!
                break;
            }

            // Closing armouredOutputStream does not close the underlying stream
            var armouredOutputStream = new ArmoredOutputStream(outputStream);
            using (var bcpgOutputStream = new BcpgOutputStream(armouredOutputStream))
            {
                armouredOutputStream.BeginClearText(HashAlgorithmTag.Sha1);

                int chr;
                while ((chr = input.ReadByte()) > 0)
                {
                    signatureGenerator.Update((byte)chr);
                    bcpgOutputStream.Write((byte)chr);
                }

                // For some reason we need to add a trailing newline
                bcpgOutputStream.Write((byte)'\n'); 

                armouredOutputStream.EndClearText();

                signatureGenerator.Generate().Encode(bcpgOutputStream);
            }
        }
Exemple #23
0
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            //IL_00fa: Unknown result type (might be due to invalid IL or missing references)
            MemoryStream     val = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream((Stream)(object)val);

            ((Stream)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(string.Concat((object)"unknown version: ", (object)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, val.ToArray(), oldFormat: true);
        }
Exemple #24
0
        public byte[] GetEncodedContents()
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            MemoryStream     val = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream((Stream)(object)val);

            bcpgOutputStream.Write(pubKeyPacket.GetEncodedContents());
            ((Stream)bcpgOutputStream).WriteByte((byte)s2kUsage);
            if (s2kUsage == 255 || s2kUsage == 254)
            {
                ((Stream)bcpgOutputStream).WriteByte((byte)encAlgorithm);
                bcpgOutputStream.WriteObject(s2k);
            }
            if (iv != null)
            {
                bcpgOutputStream.Write(iv);
            }
            if (secKeyData != null && secKeyData.Length > 0)
            {
                bcpgOutputStream.Write(secKeyData);
            }
            return(val.ToArray());
        }
Exemple #25
0
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            MemoryStream     memoryStream     = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream(memoryStream);

            bcpgOutputStream.Write(new byte[]
            {
                (byte)this.version,
                (byte)this.sigType,
                (byte)this.hashAlgorithm,
                (byte)this.keyAlgorithm
            });
            bcpgOutputStream.WriteLong(this.keyId);
            bcpgOutputStream.WriteByte((byte)this.nested);
            bcpgOut.WritePacket(PacketTag.OnePassSignature, memoryStream.ToArray(), true);
        }
        public override void Encode(BcpgOutputStream bcpgOut)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            MemoryStream     val = new MemoryStream();
            BcpgOutputStream bcpgOutputStream = new BcpgOutputStream((Stream)(object)val);

            ((Stream)bcpgOutputStream).WriteByte((byte)version);
            bcpgOutputStream.WriteLong(keyId);
            ((Stream)bcpgOutputStream).WriteByte((byte)algorithm);
            for (int i = 0; i < data.Length; i++)
            {
                bcpgOutputStream.Write(data[i]);
            }
            Platform.Dispose((Stream)(object)bcpgOutputStream);
            bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, val.ToArray(), oldFormat: true);
        }
		public override void Encode(
			BcpgOutputStream bcpgOut)
		{
			MemoryStream bOut = new MemoryStream();
			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);
		}
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            MemoryStream     bOut = new MemoryStream();
            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);
        }
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            MemoryStream     bOut = new MemoryStream();
            BcpgOutputStream pOut = new BcpgOutputStream(bOut);

            pOut.WriteByte((byte)version);

            pOut.WriteLong(keyId);

            pOut.WriteByte((byte)algorithm);

            for (int i = 0; i < data.Length; ++i)
            {
                pOut.Write(data[i]);
            }

            Platform.Dispose(pOut);

            bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, bOut.ToArray(), true);
        }
Exemple #30
0
 public override void Encode(BcpgOutputStream bcpgOut)
 {
     ((Stream)bcpgOut).WriteByte((byte)type);
     ((Stream)bcpgOut).WriteByte((byte)algorithm);
     if (type != 101)
     {
         if (type != 0)
         {
             bcpgOut.Write(iv);
         }
         if (type == 3)
         {
             ((Stream)bcpgOut).WriteByte((byte)itCount);
         }
     }
     else
     {
         ((Stream)bcpgOut).WriteByte((byte)71);
         ((Stream)bcpgOut).WriteByte((byte)78);
         ((Stream)bcpgOut).WriteByte((byte)85);
         ((Stream)bcpgOut).WriteByte((byte)protectionMode);
     }
 }
Exemple #31
0
 public override void Encode(BcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteByte((byte)this.type);
     bcpgOut.WriteByte((byte)this.algorithm);
     if (this.type != 101)
     {
         if (this.type != 0)
         {
             bcpgOut.Write(this.iv);
         }
         if (this.type == 3)
         {
             bcpgOut.WriteByte((byte)this.itCount);
             return;
         }
     }
     else
     {
         bcpgOut.WriteByte(71);
         bcpgOut.WriteByte(78);
         bcpgOut.WriteByte(85);
         bcpgOut.WriteByte((byte)this.protectionMode);
     }
 }
Exemple #32
0
        public override void Encode(
            BcpgOutputStream 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);
            }
        }
Exemple #33
0
 public override void Encode(BcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteShort((short)this.val.BitLength);
     bcpgOut.Write(this.val.ToByteArrayUnsigned());
 }
        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);
                }
            }
        }
        /// <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)
        {
            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);
                }
            }
        }
		private static void EncodeLengthAndData(
			BcpgOutputStream	pOut,
			byte[]				data)
		{
			pOut.WriteShort((short) data.Length);
			pOut.Write(data);
		}
		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);
        }
Exemple #39
0
		public byte[] GetEncodedContents()
        {
            MemoryStream bOut = new MemoryStream();
            BcpgOutputStream pOut = new BcpgOutputStream(bOut);

            pOut.Write(pubKeyPacket.GetEncodedContents());

			pOut.WriteByte((byte) s2kUsage);

			if (s2kUsage == UsageChecksum || s2kUsage == UsageSha1)
            {
                pOut.WriteByte((byte) encAlgorithm);
                pOut.WriteObject(s2k);
            }

			if (iv != null)
            {
                pOut.Write(iv);
            }

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

            return bOut.ToArray();
        }
Exemple #40
0
        public override void Encode(
            BcpgOutputStream bcpgOut)
        {
			bcpgOut.WriteShort((short) val.BitLength);
			bcpgOut.Write(val.ToByteArrayUnsigned());
        }
        public override void Encode(
			BcpgOutputStream bcpgOut)
		{
			MemoryStream bOut = new MemoryStream();
			BcpgOutputStream pOut = new BcpgOutputStream(bOut);

			pOut.WriteByte((byte) version);

			pOut.WriteLong(keyId);

			pOut.WriteByte((byte)algorithm);

            for (int i = 0; i < data.Length; ++i)
            {
                pOut.Write(data[i]);
            }

            Platform.Dispose(pOut);

            bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession , bOut.ToArray(), true);
		}
        /// <summary>
        /// Gets the encoded contents.
        /// </summary>
        /// <returns></returns>
        public byte[] GetEncodedContents()
        {
            using (var bOut = new MemoryStream())
            {
                using (var pOut = new BcpgOutputStream(bOut))
                {
                    pOut.Write(PublicKeyPacket.GetEncodedContents());
                    pOut.WriteByte((byte) this.S2KUsage);

                    if (this.S2KUsage == UsageChecksum || this.S2KUsage == UsageSha1)
                    {
                        pOut.WriteByte((byte)this.EncAlgorithm);
                        pOut.WriteObject(this.S2K);
                    }

                    if (_iv != null)
                    {
                        pOut.Write(_iv);
                    }

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

                    return bOut.ToArray();
                }
            }
        }