예제 #1
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());
        }
예제 #2
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);
        }
예제 #3
0
 internal static void Encode(
     BcpgOutputStream bcpgOut,
     BigInteger val)
 {
     bcpgOut.WriteShort((short)val.BitLength);
     bcpgOut.Write(val.ToByteArrayUnsigned());
 }
예제 #4
0
 private static void EncodeLengthAndData(
     BcpgOutputStream pOut,
     byte[]                          data)
 {
     pOut.WriteShort((short)data.Length);
     pOut.Write(data);
 }
예제 #5
0
파일: S2k.cs 프로젝트: vincent-deng/Payment
        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);
            }
        }
        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);
        }
예제 #7
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);
        }
예제 #8
0
        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);
        }
예제 #10
0
 public override void Encode(
     BcpgOutputStream bcpgOut)
 {
     bcpgOut.WriteShort((short)val.BitLength);
     bcpgOut.Write(val.ToByteArrayUnsigned());
 }