Exemplo n.º 1
0
		/// <summary>Construct a version 4 public subkey packet.</summary>
        public PublicSubkeyPacket(
            PublicKeyAlgorithmTag	algorithm,
            DateTime				time,
            IBcpgKey				key)
            : base(algorithm, time, key)
        {
        }
Exemplo n.º 2
0
        internal PublicKeyPacket(
            BcpgInputStream bcpgIn)
        {
            version = bcpgIn.ReadByte();

            time = ((uint)bcpgIn.ReadByte() << 24) | ((uint)bcpgIn.ReadByte() << 16)
                | ((uint)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte();

            if (version <= 3)
            {
                validDays = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            }

            algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();

            switch ((PublicKeyAlgorithmTag) algorithm)
            {
                case PublicKeyAlgorithmTag.RsaEncrypt:
                case PublicKeyAlgorithmTag.RsaGeneral:
                case PublicKeyAlgorithmTag.RsaSign:
                    key = new RsaPublicBcpgKey(bcpgIn);
                    break;
                case PublicKeyAlgorithmTag.Dsa:
                    key = new DsaPublicBcpgKey(bcpgIn);
                    break;
                case PublicKeyAlgorithmTag.ElGamalEncrypt:
                case PublicKeyAlgorithmTag.ElGamalGeneral:
                    key = new ElGamalPublicBcpgKey(bcpgIn);
                    break;
                default:
                    throw new IOException("unknown PGP public key algorithm encountered");
            }
        }
		private static IBufferedCipher GetKeyCipher(
            PublicKeyAlgorithmTag algorithm)
        {
            try
            {
                switch (algorithm)
                {
                    case PublicKeyAlgorithmTag.RsaEncrypt:
                    case PublicKeyAlgorithmTag.RsaGeneral:
                        return CipherUtilities.GetCipher("RSA//PKCS1Padding");
                    case PublicKeyAlgorithmTag.ElGamalEncrypt:
                    case PublicKeyAlgorithmTag.ElGamalGeneral:
                        return CipherUtilities.GetCipher("ElGamal/ECB/PKCS1Padding");
                    default:
                        throw new PgpException("unknown asymmetric algorithm: " + algorithm);
                }
            }
            catch (PgpException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new PgpException("Exception creating cipher", e);
            }
        }
        public SignaturePacket(
            int version,
            int signatureType,
            long keyId,
            PublicKeyAlgorithmTag keyAlgorithm,
            HashAlgorithmTag hashAlgorithm,
            ISignatureSubpacket[] hashedData,
            ISignatureSubpacket[] unhashedData,
            byte[] fingerprint,
            MPInteger[] signature)
        {
            this._version = version;
            this._signatureType = signatureType;
            this._keyId = keyId;
            this._keyAlgorithm = keyAlgorithm;
            this._hashAlgorithm = hashAlgorithm;
            this._hashedData = hashedData;
            this._unhashedData = unhashedData;
            this._fingerprint = fingerprint;
            this._signature = signature;

            if (hashedData != null)
            {
                SetCreationTime();
            }
        }
Exemplo n.º 5
0
		public PgpKeyPair(
            PublicKeyAlgorithmTag	algorithm,
            AsymmetricCipherKeyPair	keyPair,
            DateTime				time)
			: this(algorithm, keyPair.Public, keyPair.Private, time)
        {
        }
Exemplo n.º 6
0
		public static string GetSignatureName(
            PublicKeyAlgorithmTag	keyAlgorithm,
            HashAlgorithmTag		hashAlgorithm)
        {
            string encAlg;
			switch (keyAlgorithm)
            {
				case PublicKeyAlgorithmTag.RsaGeneral:
				case PublicKeyAlgorithmTag.RsaSign:
					encAlg = "RSA";
					break;
				case PublicKeyAlgorithmTag.Dsa:
					encAlg = "DSA";
					break;
                case PublicKeyAlgorithmTag.ECDH:
                    encAlg = "ECDH";
                    break;
                case PublicKeyAlgorithmTag.ECDsa:
                    encAlg = "ECDSA";
                    break;
                case PublicKeyAlgorithmTag.ElGamalEncrypt: // in some malformed cases.
				case PublicKeyAlgorithmTag.ElGamalGeneral:
					encAlg = "ElGamal";
					break;
				default:
					throw new PgpException("unknown algorithm tag in signature:" + keyAlgorithm);
            }

			return GetDigestName(hashAlgorithm) + "with" + encAlg;
        }
		internal PublicKeyEncSessionPacket(
			BcpgInputStream bcpgIn)
		{
			version = bcpgIn.ReadByte();

			keyId |= (long)bcpgIn.ReadByte() << 56;
			keyId |= (long)bcpgIn.ReadByte() << 48;
			keyId |= (long)bcpgIn.ReadByte() << 40;
			keyId |= (long)bcpgIn.ReadByte() << 32;
			keyId |= (long)bcpgIn.ReadByte() << 24;
			keyId |= (long)bcpgIn.ReadByte() << 16;
			keyId |= (long)bcpgIn.ReadByte() << 8;
			keyId |= (uint)bcpgIn.ReadByte();

			algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();

			switch ((PublicKeyAlgorithmTag) algorithm)
			{
				case PublicKeyAlgorithmTag.RsaEncrypt:
				case PublicKeyAlgorithmTag.RsaGeneral:
					data = new BigInteger[]{ new MPInteger(bcpgIn).Value };
					break;
				case PublicKeyAlgorithmTag.ElGamalEncrypt:
				case PublicKeyAlgorithmTag.ElGamalGeneral:
					data = new BigInteger[]
					{
						new MPInteger(bcpgIn).Value,
						new MPInteger(bcpgIn).Value
					};
					break;
				default:
					throw new IOException("unknown PGP public key algorithm encountered");
			}
		}
 /// <summary>
 /// Construct a version 4 public key packet.
 /// </summary>
 /// <param name="algorithm">The algorithm.</param>
 /// <param name="time">The time.</param>
 /// <param name="key">The key.</param>
 public PublicKeyPacket(PublicKeyAlgorithmTag algorithm, DateTime time, IBcpgPublicKey key)
 {
     _version = 4;
     _time = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L;
     _algorithm = algorithm;
     _key = key;
 }
Exemplo n.º 9
0
        public static string GetAlgorithm(
            PublicKeyAlgorithmTag algId)
        {
            switch (algId)
            {
                case PublicKeyAlgorithmTag.RsaGeneral:
                    return "RsaGeneral";
                case PublicKeyAlgorithmTag.RsaEncrypt:
                    return "RsaEncrypt";
                case PublicKeyAlgorithmTag.RsaSign:
                    return "RsaSign";
                case PublicKeyAlgorithmTag.ElGamalEncrypt:
                    return "ElGamalEncrypt";
                case PublicKeyAlgorithmTag.Dsa:
                    return "DSA";
                case PublicKeyAlgorithmTag.EC:
                    return "EC";
                case PublicKeyAlgorithmTag.ECDsa:
                    return "ECDSA";
                case PublicKeyAlgorithmTag.ElGamalGeneral:
                    return "ElGamalGeneral";
                case PublicKeyAlgorithmTag.DiffieHellman:
                    return "DiffieHellman";
            }

            return "unknown";
        }
        /// <summary>Create a generator for the passed in keyAlgorithm and hashAlgorithm codes.</summary>
        public PgpSignatureGenerator(PublicKeyAlgorithmTag keyAlgorithm, HashAlgorithmTag hashAlgorithm)
        {
            _keyAlgorithm = keyAlgorithm;
            _hashAlgorithm = hashAlgorithm;

            _dig = DigestUtilities.GetDigest(PgpUtilities.GetDigestName(hashAlgorithm));
            _sig = SignerUtilities.GetSigner(PgpUtilities.GetSignatureName(keyAlgorithm, hashAlgorithm));
        }
 public PublicKeyEncSessionPacket(long keyId, PublicKeyAlgorithmTag algorithm, BigInteger[] data, byte[] extraData)
 {
     _version = 3;
     _keyId = keyId;
     _algorithm = algorithm;
     _data = (IBigInteger[])data.Clone();
     _extraData = extraData != null ? (byte[])extraData.Clone() : null;
 }
Exemplo n.º 12
0
        public RevocationKey(
			bool					isCritical,
			RevocationKeyTag		signatureClass,
			PublicKeyAlgorithmTag	keyAlgorithm,
			byte[]					fingerprint)
			: base(SignatureSubpacketTag.RevocationKey, isCritical, false,
				CreateData(signatureClass, keyAlgorithm, fingerprint))
		{
		}
Exemplo n.º 13
0
		public PgpKeyPair(
            PublicKeyAlgorithmTag	algorithm,
            AsymmetricKeyParameter	pubKey,
            AsymmetricKeyParameter	privKey,
            DateTime				time)
        {
            this.pub = new PgpPublicKey(algorithm, pubKey, time);
			this.priv = new PgpPrivateKey(privKey, pub.KeyId);
        }
        /// <summary>
        /// Create a PgpPublicKey from the passed in lightweight one.
        /// </summary>
        /// <remarks>
        /// Note: the time passed in affects the value of the key's keyId, so you probably only want
        /// to do this once for a lightweight key, or make sure you keep track of the time you used.
        /// </remarks>
        /// <param name="algorithm">Asymmetric algorithm type representing the public key.</param>
        /// <param name="pubKey">Actual public key to associate.</param>
        /// <param name="time">Date of creation.</param>
        /// <exception cref="ArgumentException">If <c>pubKey</c> is not public.</exception>
        /// <exception cref="PgpException">On key creation problem.</exception>
        public PgpPublicKey(PublicKeyAlgorithmTag algorithm, IAsymmetricKeyParameter pubKey, DateTime time)
        {
            if (pubKey.IsPrivate)
                throw new ArgumentException(@"Expected a public key", "pubKey");

            IBcpgPublicKey bcpgKey;

            if (pubKey is RsaKeyParameters)
            {
                var rK = (RsaKeyParameters)pubKey;

                bcpgKey = new RsaPublicBcpgKey(rK.Modulus, rK.Exponent);
            }
            else if (pubKey is DsaPublicKeyParameters)
            {
                var dK = (DsaPublicKeyParameters)pubKey;
                var dP = dK.Parameters;

                bcpgKey = new DsaPublicBcpgKey(dP.P, dP.Q, dP.G, dK.Y);
            }
            else if (pubKey is ElGamalPublicKeyParameters)
            {
                var eK = (ElGamalPublicKeyParameters)pubKey;
                var eS = eK.Parameters;

                bcpgKey = new ElGamalPublicBcpgKey(eS.P, eS.G, eK.Y);
            }
            else if (pubKey is ECDHPublicKeyParameters)
            {
                var ecdh = (ECDHPublicKeyParameters)pubKey;

                bcpgKey = new ECDHPublicBcpgKey(ecdh.Q, ecdh.PublicKeyParamSet, ecdh.HashAlgorithm, ecdh.SymmetricKeyAlgorithm);
            }
            else if (pubKey is ECPublicKeyParameters)
            {
                var ecdsa = (ECPublicKeyParameters)pubKey;
                bcpgKey = new ECDSAPublicBcpgKey(ecdsa.Q, ecdsa.PublicKeyParamSet);
            }
            else
            {
                throw new PgpException("unknown key class");
            }

            _publicPk = new PublicKeyPacket(algorithm, time, bcpgKey);
            _ids = Platform.CreateArrayList();
            _idSigs = Platform.CreateArrayList<IList<IPgpSignature>>();

            try
            {
                Init();
            }
            catch (IOException e)
            {
                throw new PgpException("exception calculating keyId", e);
            }
        }
Exemplo n.º 15
0
		/// <summary>Construct a version 4 public key packet.</summary>
        public PublicKeyPacket(
            PublicKeyAlgorithmTag	algorithm,
            DateTime				time,
            IBcpgKey				key)
        {
			this.version = 4;
            this.time = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L;
            this.algorithm = algorithm;
            this.key = key;
        }
		public PublicKeyEncSessionPacket(
			long					keyId,
			PublicKeyAlgorithmTag	algorithm,
			BigInteger[]			data)
		{
			this.version = 3;
			this.keyId = keyId;
			this.algorithm = algorithm;
			this.data = (BigInteger[]) data.Clone();
		}
		/// <summary>Create a generator for the passed in keyAlgorithm and hashAlgorithm codes.</summary>
        public PgpV3SignatureGenerator(
            PublicKeyAlgorithmTag	keyAlgorithm,
            HashAlgorithmTag		hashAlgorithm)
        {
            this.keyAlgorithm = keyAlgorithm;
            this.hashAlgorithm = hashAlgorithm;

            dig = DigestUtilities.GetDigest(PgpUtilities.GetDigestName(hashAlgorithm));
            sig = SignerUtilities.GetSigner(PgpUtilities.GetSignatureName(keyAlgorithm, hashAlgorithm));
        }
Exemplo n.º 18
0
		private static byte[] CreateData(
			RevocationKeyTag		signatureClass,
			PublicKeyAlgorithmTag	keyAlgorithm,
			byte[]					fingerprint)
		{
			byte[] data = new byte[2 + fingerprint.Length];
			data[0] = (byte)signatureClass;
			data[1] = (byte)keyAlgorithm;
			Array.Copy(fingerprint, 0, data, 2, fingerprint.Length);
			return data;
		}
Exemplo n.º 19
0
 /**
 * Generate a version 4 signature packet.
 *
 * @param signatureType
 * @param keyAlgorithm
 * @param hashAlgorithm
 * @param hashedData
 * @param unhashedData
 * @param fingerprint
 * @param signature
 */
 public SignaturePacket(
     int						signatureType,
     long					keyId,
     PublicKeyAlgorithmTag	keyAlgorithm,
     HashAlgorithmTag		hashAlgorithm,
     SignatureSubpacket[]	hashedData,
     SignatureSubpacket[]	unhashedData,
     byte[]					fingerprint,
     MPInteger[]				signature)
     : this(4, signatureType, keyId, keyAlgorithm, hashAlgorithm, hashedData, unhashedData, fingerprint, signature)
 {
 }
Exemplo n.º 20
0
 /**
 * Generate a version 2/3 signature packet.
 *
 * @param signatureType
 * @param keyAlgorithm
 * @param hashAlgorithm
 * @param fingerprint
 * @param signature
 */
 public SignaturePacket(
     int						version,
     int						signatureType,
     long					keyId,
     PublicKeyAlgorithmTag	keyAlgorithm,
     HashAlgorithmTag		hashAlgorithm,
     long					creationTime,
     byte[]					fingerprint,
     MPInteger[]				signature)
     : this(version, signatureType, keyId, keyAlgorithm, hashAlgorithm, null, null, fingerprint, signature)
 {
     this.creationTime = creationTime;
 }
		public OnePassSignaturePacket(
			int						sigType,
			HashAlgorithmTag		hashAlgorithm,
			PublicKeyAlgorithmTag	keyAlgorithm,
			long					keyId,
			bool					isNested)
		{
			this.version = 3;
			this.sigType = sigType;
			this.hashAlgorithm = hashAlgorithm;
			this.keyAlgorithm = keyAlgorithm;
			this.keyId = keyId;
			this.nested = (isNested) ? 0 : 1;
		}
        public PublicKeyEncSessionPacket(
			long                    keyId,
			PublicKeyAlgorithmTag   algorithm,
			byte[][]                data)
		{
			this.version = 3;
			this.keyId = keyId;
			this.algorithm = algorithm;
            this.data = new byte[data.Length][];
            for (int i = 0; i < data.Length; ++i)
            {
                this.data[i] = Arrays.Clone(data[i]);
            }
		}
 public PgpSecretKey(
     int certificationLevel,
     PublicKeyAlgorithmTag algorithm,
     IAsymmetricKeyParameter pubKey,
     IAsymmetricKeyParameter privKey,
     DateTime time,
     string id,
     SymmetricKeyAlgorithmTag encAlgorithm,
     char[] passPhrase,
     bool useSha1,
     PgpSignatureSubpacketVector hashedPackets,
     PgpSignatureSubpacketVector unhashedPackets,
     SecureRandom rand)
     : this(certificationLevel, new PgpKeyPair(algorithm, pubKey, privKey, time), id, encAlgorithm, passPhrase, useSha1, hashedPackets, unhashedPackets, rand)
 {
 }
Exemplo n.º 24
0
        /// <summary>
        /// Create a PgpPublicKey from the passed in JCA one.
        /// <p>
        /// Note: the time passed in affects the value of the key's keyId, so you probably only want
        /// to do this once for a JCA key, or make sure you keep track of the time you used.</p>
        /// </summary>
        public PgpPublicKey(
            PublicKeyAlgorithmTag	algorithm,
            AsymmetricKeyParameter	pubKey,
            DateTime				time)
        {
            if (pubKey.IsPrivate)
                throw new ArgumentException("Expected a public key", "pubKey");

            IBcpgKey bcpgKey;
            if (pubKey is RsaKeyParameters)
            {
                RsaKeyParameters rK = (RsaKeyParameters) pubKey;

                bcpgKey = new RsaPublicBcpgKey(rK.Modulus, rK.Exponent);
            }
            else if (pubKey is DsaPublicKeyParameters)
            {
                DsaPublicKeyParameters dK = (DsaPublicKeyParameters) pubKey;
                DsaParameters dP = dK.Parameters;

                bcpgKey = new DsaPublicBcpgKey(dP.P, dP.Q, dP.G, dK.Y);
            }
            else if (pubKey is ElGamalPublicKeyParameters)
            {
                ElGamalPublicKeyParameters eK = (ElGamalPublicKeyParameters) pubKey;
                ElGamalParameters eS = eK.Parameters;

                bcpgKey = new ElGamalPublicBcpgKey(eS.P, eS.G, eK.Y);
            }
            else
            {
                throw new PgpException("unknown key class");
            }

            this.publicPk = new PublicKeyPacket(algorithm, time, bcpgKey);
            this.ids = new ArrayList();
            this.idSigs = new ArrayList();

            try
            {
                Init();
            }
            catch (IOException e)
            {
                throw new PgpException("exception calculating keyId", e);
            }
        }
		internal OnePassSignaturePacket(
			BcpgInputStream	bcpgIn)
		{
			version = bcpgIn.ReadByte();
			sigType = bcpgIn.ReadByte();
			hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();
			keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();

			keyId |= (long)bcpgIn.ReadByte() << 56;
			keyId |= (long)bcpgIn.ReadByte() << 48;
			keyId |= (long)bcpgIn.ReadByte() << 40;
			keyId |= (long)bcpgIn.ReadByte() << 32;
			keyId |= (long)bcpgIn.ReadByte() << 24;
			keyId |= (long)bcpgIn.ReadByte() << 16;
			keyId |= (long)bcpgIn.ReadByte() << 8;
			keyId |= (uint)bcpgIn.ReadByte();

			nested = bcpgIn.ReadByte();
		}
        internal PublicKeyEncSessionPacket(BcpgInputStream bcpgIn)
        {
            _version = bcpgIn.ReadByte();

            _keyId |= (long)bcpgIn.ReadByte() << 56;
            _keyId |= (long)bcpgIn.ReadByte() << 48;
            _keyId |= (long)bcpgIn.ReadByte() << 40;
            _keyId |= (long)bcpgIn.ReadByte() << 32;
            _keyId |= (long)bcpgIn.ReadByte() << 24;
            _keyId |= (long)bcpgIn.ReadByte() << 16;
            _keyId |= (long)bcpgIn.ReadByte() << 8;
            _keyId |= (uint)bcpgIn.ReadByte();

            _algorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();

            switch (_algorithm)
            {
                case PublicKeyAlgorithmTag.RsaEncrypt:
                case PublicKeyAlgorithmTag.RsaGeneral:
                    _data = new[] { new MPInteger(bcpgIn).Value };
                    break;
                case PublicKeyAlgorithmTag.ElGamalEncrypt:
                case PublicKeyAlgorithmTag.ElGamalGeneral:
                    _data = new[]
                    {
                        new MPInteger(bcpgIn).Value,
                        new MPInteger(bcpgIn).Value
                    };
                    break;

                case PublicKeyAlgorithmTag.Ecdh:
                    _data = new[] { new MPInteger(bcpgIn).Value };
                    var length = bcpgIn.ReadByte();
                    if (length > 0xFF)
                        throw new IOException("EC DH symmetric key data is too long.");
                    _extraData = new byte[length];
                    bcpgIn.ReadFully(_extraData, 0, length);
                    break;
                default:
                    throw new IOException("unknown PGP public key algorithm encountered");
            }
        }
Exemplo n.º 27
0
 public SignaturePacket(
     int						version,
     int						signatureType,
     long					keyId,
     PublicKeyAlgorithmTag	keyAlgorithm,
     HashAlgorithmTag		hashAlgorithm,
     SignatureSubpacket[]	hashedData,
     SignatureSubpacket[]	unhashedData,
     byte[]					fingerprint,
     MPInteger[]				signature)
 {
     this.version = version;
     this.signatureType = signatureType;
     this.keyId = keyId;
     this.keyAlgorithm = keyAlgorithm;
     this.hashAlgorithm = hashAlgorithm;
     this.hashedData = hashedData;
     this.unhashedData = unhashedData;
     this.fingerprint = fingerprint;
     this.signature = signature;
 }
		internal PublicKeyEncSessionPacket(
			BcpgInputStream bcpgIn)
		{
			version = bcpgIn.ReadByte();

			keyId |= (long)bcpgIn.ReadByte() << 56;
			keyId |= (long)bcpgIn.ReadByte() << 48;
			keyId |= (long)bcpgIn.ReadByte() << 40;
			keyId |= (long)bcpgIn.ReadByte() << 32;
			keyId |= (long)bcpgIn.ReadByte() << 24;
			keyId |= (long)bcpgIn.ReadByte() << 16;
			keyId |= (long)bcpgIn.ReadByte() << 8;
			keyId |= (uint)bcpgIn.ReadByte();

			algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();

			switch ((PublicKeyAlgorithmTag) algorithm)
			{
				case PublicKeyAlgorithmTag.RsaEncrypt:
				case PublicKeyAlgorithmTag.RsaGeneral:
					data = new byte[][]{ new MPInteger(bcpgIn).GetEncoded() };
					break;
				case PublicKeyAlgorithmTag.ElGamalEncrypt:
				case PublicKeyAlgorithmTag.ElGamalGeneral:
                    MPInteger p = new MPInteger(bcpgIn);
                    MPInteger g = new MPInteger(bcpgIn);
					data = new byte[][]{
                        p.GetEncoded(),
                        g.GetEncoded(),
                    };
					break;
                case PublicKeyAlgorithmTag.ECDH:
                    data = new byte[][]{ Streams.ReadAll(bcpgIn) };
                    break;
				default:
					throw new IOException("unknown PGP public key algorithm encountered");
			}
		}
Exemplo n.º 29
0
        internal SignaturePacket(BcpgInputStream bcpgIn)
        {
            this.version = bcpgIn.ReadByte();
            if (this.version == 3 || this.version == 2)
            {
                bcpgIn.ReadByte();
                this.signatureType = bcpgIn.ReadByte();
                this.creationTime  = ((long)bcpgIn.ReadByte() << 24 | (long)bcpgIn.ReadByte() << 16 | (long)bcpgIn.ReadByte() << 8 | (long)((ulong)bcpgIn.ReadByte())) * 1000L;
                this.keyId        |= (long)bcpgIn.ReadByte() << 56;
                this.keyId        |= (long)bcpgIn.ReadByte() << 48;
                this.keyId        |= (long)bcpgIn.ReadByte() << 40;
                this.keyId        |= (long)bcpgIn.ReadByte() << 32;
                this.keyId        |= (long)bcpgIn.ReadByte() << 24;
                this.keyId        |= (long)bcpgIn.ReadByte() << 16;
                this.keyId        |= (long)bcpgIn.ReadByte() << 8;
                this.keyId        |= (long)((ulong)bcpgIn.ReadByte());
                this.keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
                this.hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
            }
            else
            {
                if (this.version != 4)
                {
                    throw new Exception("unsupported version: " + this.version);
                }
                this.signatureType = bcpgIn.ReadByte();
                this.keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
                this.hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
                int    num    = bcpgIn.ReadByte() << 8 | bcpgIn.ReadByte();
                byte[] buffer = new byte[num];
                bcpgIn.ReadFully(buffer);
                SignatureSubpacketsParser signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer, false));
                IList list = Platform.CreateArrayList();
                SignatureSubpacket value;
                while ((value = signatureSubpacketsParser.ReadPacket()) != null)
                {
                    list.Add(value);
                }
                this.hashedData = new SignatureSubpacket[list.Count];
                for (int num2 = 0; num2 != this.hashedData.Length; num2++)
                {
                    SignatureSubpacket signatureSubpacket = (SignatureSubpacket)list[num2];
                    if (signatureSubpacket is IssuerKeyId)
                    {
                        this.keyId = ((IssuerKeyId)signatureSubpacket).KeyId;
                    }
                    else if (signatureSubpacket is SignatureCreationTime)
                    {
                        this.creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime());
                    }
                    this.hashedData[num2] = signatureSubpacket;
                }
                int    num3    = bcpgIn.ReadByte() << 8 | bcpgIn.ReadByte();
                byte[] buffer2 = new byte[num3];
                bcpgIn.ReadFully(buffer2);
                signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer2, false));
                list.Clear();
                while ((value = signatureSubpacketsParser.ReadPacket()) != null)
                {
                    list.Add(value);
                }
                this.unhashedData = new SignatureSubpacket[list.Count];
                for (int num4 = 0; num4 != this.unhashedData.Length; num4++)
                {
                    SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list[num4];
                    if (signatureSubpacket2 is IssuerKeyId)
                    {
                        this.keyId = ((IssuerKeyId)signatureSubpacket2).KeyId;
                    }
                    this.unhashedData[num4] = signatureSubpacket2;
                }
            }
            this.fingerprint = new byte[2];
            bcpgIn.ReadFully(this.fingerprint);
            PublicKeyAlgorithmTag publicKeyAlgorithmTag = this.keyAlgorithm;

            switch (publicKeyAlgorithmTag)
            {
            case PublicKeyAlgorithmTag.RsaGeneral:
            case PublicKeyAlgorithmTag.RsaSign:
            {
                MPInteger mPInteger = new MPInteger(bcpgIn);
                this.signature = new MPInteger[]
                {
                    mPInteger
                };
                return;
            }

            case PublicKeyAlgorithmTag.RsaEncrypt:
                break;

            default:
                switch (publicKeyAlgorithmTag)
                {
                case PublicKeyAlgorithmTag.ElGamalEncrypt:
                case PublicKeyAlgorithmTag.ElGamalGeneral:
                {
                    MPInteger mPInteger2 = new MPInteger(bcpgIn);
                    MPInteger mPInteger3 = new MPInteger(bcpgIn);
                    MPInteger mPInteger4 = new MPInteger(bcpgIn);
                    this.signature = new MPInteger[]
                    {
                        mPInteger2,
                        mPInteger3,
                        mPInteger4
                    };
                    return;
                }

                case PublicKeyAlgorithmTag.Dsa:
                {
                    MPInteger mPInteger5 = new MPInteger(bcpgIn);
                    MPInteger mPInteger6 = new MPInteger(bcpgIn);
                    this.signature = new MPInteger[]
                    {
                        mPInteger5,
                        mPInteger6
                    };
                    return;
                }
                }
                break;
            }
            if (this.keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && this.keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
            {
                this.signature = null;
                MemoryStream memoryStream = new MemoryStream();
                int          num5;
                while ((num5 = bcpgIn.ReadByte()) >= 0)
                {
                    memoryStream.WriteByte((byte)num5);
                }
                this.signatureEncoding = memoryStream.ToArray();
                return;
            }
            throw new IOException("unknown signature key algorithm: " + this.keyAlgorithm);
        }
        /// <summary>
        /// Generate public/secret key ring file.
        /// </summary>
        /// <param name="identity">
        /// The identity.
        /// </param>
        /// <param name="password">
        /// The password.
        /// </param>
        /// <param name="publicKeyFile">
        /// The public key file path.
        /// </param>
        /// <param name="privateKeyFile">
        /// The private key file path.
        /// </param>
        /// <param name="expires">
        /// When, if ever, should the key expire; null means never.
        /// </param>
        /// <param name="armor">
        /// Should output as ASCII armor?
        /// </param>
        /// <param name="signKeyLength">
        /// Signing keypair length.
        /// </param>
        /// <param name="signGenerator">
        /// Signing key generator type.
        /// </param>
        /// <param name="signingAlgorithm">
        /// The signing algorithm.
        /// </param>
        /// <param name="encryptKeyLength">
        /// Encryption keypair length.
        /// </param>
        /// <param name="encryptGenerator">
        /// Encryption key generator type.
        /// </param>
        /// <param name="encryptionAlgorithm">
        /// The encryption algorithm.
        /// </param>
        /// <param name="symmetricAlgorithm">
        /// The symmetric encryption algorithm.
        /// </param>
        public static void GenerateKeyRing(
            string identity,
            string password,
            string publicKeyFile,
            string privateKeyFile,
            DateTime?expires,
            bool armor           = false,
            int signKeyLength    = 2048,
            string signGenerator = "RSA",
            PublicKeyAlgorithmTag signingAlgorithm = PublicKeyAlgorithmTag.RsaSign,
            int encryptKeyLength    = 2048,
            string encryptGenerator = "RSA",
            PublicKeyAlgorithmTag encryptionAlgorithm   = PublicKeyAlgorithmTag.RsaEncrypt,
            SymmetricKeyAlgorithmTag symmetricAlgorithm = SymmetricKeyAlgorithmTag.Aes256)
        {
            var krgen = CreateKeyRingGenerator(
                identity,
                password,
                expires,
                signKeyLength,
                signGenerator,
                signingAlgorithm,
                encryptKeyLength,
                encryptGenerator,
                encryptionAlgorithm,
                symmetricAlgorithm);

            // Generate public key ring, dump to file.
            var pkr = krgen.GeneratePublicKeyRing();

            using (var pubout = (Stream) new FileStream(publicKeyFile, FileMode.Create))
            {
                Stream wrapped = pubout;
                if (armor)
                {
                    wrapped = new ArmoredOutputStream(pubout);
                }

                pkr.Encode(wrapped);
                wrapped.Flush();

                if (armor)
                {
                    wrapped.Dispose();
                }
            }

            // Generate private key, dump to file.
            var skr = krgen.GenerateSecretKeyRing();

            using (var secout = (Stream) new FileStream(privateKeyFile, FileMode.Create))
            {
                Stream wrapped = secout;
                if (armor)
                {
                    wrapped = new ArmoredOutputStream(secout);
                }

                skr.Encode(wrapped);
                wrapped.Flush();

                if (armor)
                {
                    wrapped.Dispose();
                }
            }
        }
Exemplo n.º 31
0
 public RevocationKey(bool isCritical, RevocationKeyTag signatureClass, PublicKeyAlgorithmTag keyAlgorithm, byte[] fingerprint)
     : base(SignatureSubpacketTag.RevocationKey, isCritical, isLongLength: false, CreateData(signatureClass, keyAlgorithm, fingerprint))
 {
 }
 public PgpSignatureFactoryBuilder(PublicKeyAlgorithmTag keyAlg, HashAlgorithmTag hashAlg)
 {
     this.keyAlg  = keyAlg;
     this.hashAlg = hashAlg;
 }
Exemplo n.º 33
0
    internal SignaturePacket(BcpgInputStream bcpgIn)
    {
        version = bcpgIn.ReadByte();
        if (version == 3 || version == 2)
        {
            bcpgIn.ReadByte();
            signatureType = bcpgIn.ReadByte();
            creationTime  = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16) | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000;
            keyId        |= (long)bcpgIn.ReadByte() << 56;
            keyId        |= (long)bcpgIn.ReadByte() << 48;
            keyId        |= (long)bcpgIn.ReadByte() << 40;
            keyId        |= (long)bcpgIn.ReadByte() << 32;
            keyId        |= (long)bcpgIn.ReadByte() << 24;
            keyId        |= (long)bcpgIn.ReadByte() << 16;
            keyId        |= (long)bcpgIn.ReadByte() << 8;
            keyId        |= (uint)bcpgIn.ReadByte();
            keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
            hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
        }
        else
        {
            if (version != 4)
            {
                throw new Exception("unsupported version: " + version);
            }
            signatureType = bcpgIn.ReadByte();
            keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
            hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
            int    num    = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            byte[] buffer = new byte[num];
            bcpgIn.ReadFully(buffer);
            SignatureSubpacketsParser signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer, writable: false));
            IList list = Platform.CreateArrayList();
            SignatureSubpacket value;
            while ((value = signatureSubpacketsParser.ReadPacket()) != null)
            {
                list.Add(value);
            }
            hashedData = new SignatureSubpacket[list.Count];
            for (int i = 0; i != hashedData.Length; i++)
            {
                SignatureSubpacket signatureSubpacket = (SignatureSubpacket)list[i];
                if (signatureSubpacket is IssuerKeyId)
                {
                    keyId = ((IssuerKeyId)signatureSubpacket).KeyId;
                }
                else if (signatureSubpacket is SignatureCreationTime)
                {
                    creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket).GetTime());
                }
                hashedData[i] = signatureSubpacket;
            }
            int    num2    = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
            byte[] buffer2 = new byte[num2];
            bcpgIn.ReadFully(buffer2);
            signatureSubpacketsParser = new SignatureSubpacketsParser(new MemoryStream(buffer2, writable: false));
            list.Clear();
            while ((value = signatureSubpacketsParser.ReadPacket()) != null)
            {
                list.Add(value);
            }
            unhashedData = new SignatureSubpacket[list.Count];
            for (int j = 0; j != unhashedData.Length; j++)
            {
                SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list[j];
                if (signatureSubpacket2 is IssuerKeyId)
                {
                    keyId = ((IssuerKeyId)signatureSubpacket2).KeyId;
                }
                unhashedData[j] = signatureSubpacket2;
            }
        }
        fingerprint = new byte[2];
        bcpgIn.ReadFully(fingerprint);
        switch (keyAlgorithm)
        {
        case PublicKeyAlgorithmTag.RsaGeneral:
        case PublicKeyAlgorithmTag.RsaSign:
        {
            MPInteger mPInteger8 = new MPInteger(bcpgIn);
            signature = new MPInteger[1]
            {
                mPInteger8
            };
            return;
        }

        case PublicKeyAlgorithmTag.Dsa:
        {
            MPInteger mPInteger6 = new MPInteger(bcpgIn);
            MPInteger mPInteger7 = new MPInteger(bcpgIn);
            signature = new MPInteger[2]
            {
                mPInteger6,
                mPInteger7
            };
            return;
        }

        case PublicKeyAlgorithmTag.ElGamalEncrypt:
        case PublicKeyAlgorithmTag.ElGamalGeneral:
        {
            MPInteger mPInteger3 = new MPInteger(bcpgIn);
            MPInteger mPInteger4 = new MPInteger(bcpgIn);
            MPInteger mPInteger5 = new MPInteger(bcpgIn);
            signature = new MPInteger[3]
            {
                mPInteger3,
                mPInteger4,
                mPInteger5
            };
            return;
        }

        case PublicKeyAlgorithmTag.ECDsa:
        {
            MPInteger mPInteger  = new MPInteger(bcpgIn);
            MPInteger mPInteger2 = new MPInteger(bcpgIn);
            signature = new MPInteger[2]
            {
                mPInteger,
                mPInteger2
            };
            return;
        }
        }
        if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
        {
            signature = null;
            MemoryStream memoryStream = new MemoryStream();
            int          num3;
            while ((num3 = bcpgIn.ReadByte()) >= 0)
            {
                memoryStream.WriteByte((byte)num3);
            }
            signatureEncoding = memoryStream.ToArray();
            return;
        }
        throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
    }
Exemplo n.º 34
0
        internal SignaturePacket(BcpgInputStream bcpgIn)
        {
            //IL_018f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0199: Expected O, but got Unknown
            //IL_025a: Unknown result type (might be due to invalid IL or missing references)
            //IL_0264: Expected O, but got Unknown
            //IL_0422: Unknown result type (might be due to invalid IL or missing references)
            //IL_0429: Expected O, but got Unknown
            //IL_0464: Unknown result type (might be due to invalid IL or missing references)
            version = ((Stream)bcpgIn).ReadByte();
            if (version == 3 || version == 2)
            {
                ((Stream)bcpgIn).ReadByte();
                signatureType = ((Stream)bcpgIn).ReadByte();
                creationTime  = (((long)((Stream)bcpgIn).ReadByte() << 24) | ((long)((Stream)bcpgIn).ReadByte() << 16) | ((long)((Stream)bcpgIn).ReadByte() << 8) | (uint)((Stream)bcpgIn).ReadByte()) * 1000;
                keyId        |= (long)((Stream)bcpgIn).ReadByte() << 56;
                keyId        |= (long)((Stream)bcpgIn).ReadByte() << 48;
                keyId        |= (long)((Stream)bcpgIn).ReadByte() << 40;
                keyId        |= (long)((Stream)bcpgIn).ReadByte() << 32;
                keyId        |= (long)((Stream)bcpgIn).ReadByte() << 24;
                keyId        |= (long)((Stream)bcpgIn).ReadByte() << 16;
                keyId        |= (long)((Stream)bcpgIn).ReadByte() << 8;
                keyId        |= (uint)((Stream)bcpgIn).ReadByte();
                keyAlgorithm  = (PublicKeyAlgorithmTag)((Stream)bcpgIn).ReadByte();
                hashAlgorithm = (HashAlgorithmTag)((Stream)bcpgIn).ReadByte();
            }
            else
            {
                if (version != 4)
                {
                    throw new global::System.Exception(string.Concat((object)"unsupported version: ", (object)version));
                }
                signatureType = ((Stream)bcpgIn).ReadByte();
                keyAlgorithm  = (PublicKeyAlgorithmTag)((Stream)bcpgIn).ReadByte();
                hashAlgorithm = (HashAlgorithmTag)((Stream)bcpgIn).ReadByte();
                int    num   = (((Stream)bcpgIn).ReadByte() << 8) | ((Stream)bcpgIn).ReadByte();
                byte[] array = new byte[num];
                bcpgIn.ReadFully(array);
                SignatureSubpacketsParser        signatureSubpacketsParser = new SignatureSubpacketsParser((Stream) new MemoryStream(array, false));
                global::System.Collections.IList list = Platform.CreateArrayList();
                SignatureSubpacket signatureSubpacket;
                while ((signatureSubpacket = signatureSubpacketsParser.ReadPacket()) != null)
                {
                    list.Add((object)signatureSubpacket);
                }
                hashedData = new SignatureSubpacket[((global::System.Collections.ICollection)list).get_Count()];
                for (int i = 0; i != hashedData.Length; i++)
                {
                    SignatureSubpacket signatureSubpacket2 = (SignatureSubpacket)list.get_Item(i);
                    if (signatureSubpacket2 is IssuerKeyId)
                    {
                        keyId = ((IssuerKeyId)signatureSubpacket2).KeyId;
                    }
                    else if (signatureSubpacket2 is SignatureCreationTime)
                    {
                        creationTime = DateTimeUtilities.DateTimeToUnixMs(((SignatureCreationTime)signatureSubpacket2).GetTime());
                    }
                    hashedData[i] = signatureSubpacket2;
                }
                int    num2   = (((Stream)bcpgIn).ReadByte() << 8) | ((Stream)bcpgIn).ReadByte();
                byte[] array2 = new byte[num2];
                bcpgIn.ReadFully(array2);
                signatureSubpacketsParser = new SignatureSubpacketsParser((Stream) new MemoryStream(array2, false));
                list.Clear();
                while ((signatureSubpacket = signatureSubpacketsParser.ReadPacket()) != null)
                {
                    list.Add((object)signatureSubpacket);
                }
                unhashedData = new SignatureSubpacket[((global::System.Collections.ICollection)list).get_Count()];
                for (int j = 0; j != unhashedData.Length; j++)
                {
                    SignatureSubpacket signatureSubpacket3 = (SignatureSubpacket)list.get_Item(j);
                    if (signatureSubpacket3 is IssuerKeyId)
                    {
                        keyId = ((IssuerKeyId)signatureSubpacket3).KeyId;
                    }
                    unhashedData[j] = signatureSubpacket3;
                }
            }
            fingerprint = new byte[2];
            bcpgIn.ReadFully(fingerprint);
            switch (keyAlgorithm)
            {
            case PublicKeyAlgorithmTag.RsaGeneral:
            case PublicKeyAlgorithmTag.RsaSign:
            {
                MPInteger mPInteger8 = new MPInteger(bcpgIn);
                signature = new MPInteger[1] {
                    mPInteger8
                };
                return;
            }

            case PublicKeyAlgorithmTag.Dsa:
            {
                MPInteger mPInteger6 = new MPInteger(bcpgIn);
                MPInteger mPInteger7 = new MPInteger(bcpgIn);
                signature = new MPInteger[2] {
                    mPInteger6, mPInteger7
                };
                return;
            }

            case PublicKeyAlgorithmTag.ElGamalEncrypt:
            case PublicKeyAlgorithmTag.ElGamalGeneral:
            {
                MPInteger mPInteger3 = new MPInteger(bcpgIn);
                MPInteger mPInteger4 = new MPInteger(bcpgIn);
                MPInteger mPInteger5 = new MPInteger(bcpgIn);
                signature = new MPInteger[3] {
                    mPInteger3, mPInteger4, mPInteger5
                };
                return;
            }

            case PublicKeyAlgorithmTag.ECDsa:
            {
                MPInteger mPInteger  = new MPInteger(bcpgIn);
                MPInteger mPInteger2 = new MPInteger(bcpgIn);
                signature = new MPInteger[2] {
                    mPInteger, mPInteger2
                };
                return;
            }
            }
            if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
            {
                signature = null;
                MemoryStream val = new MemoryStream();
                int          num3;
                while ((num3 = ((Stream)bcpgIn).ReadByte()) >= 0)
                {
                    ((Stream)val).WriteByte((byte)num3);
                }
                signatureEncoding = val.ToArray();
                return;
            }
            throw new IOException(string.Concat((object)"unknown signature key algorithm: ", (object)keyAlgorithm));
        }
Exemplo n.º 35
0
 public SignaturePacket(int signatureType, long keyId, PublicKeyAlgorithmTag keyAlgorithm, HashAlgorithmTag hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerprint, MPInteger[] signature)
     : this(4, signatureType, keyId, keyAlgorithm, hashAlgorithm, hashedData, unhashedData, fingerprint, signature)
 {
 }
Exemplo n.º 36
0
 public PgpSignatureIdentifier(long keyId, PublicKeyAlgorithmTag keyAlgorithm, HashAlgorithmTag hashAlgorithm)
 {
     this.mKeyId         = keyId;
     this.mKeyAlgorithm  = keyAlgorithm;
     this.mHashAlgorithm = hashAlgorithm;
 }
Exemplo n.º 37
0
 public PgpKeyPair(PublicKeyAlgorithmTag algorithm, AsymmetricCipherKeyPair keyPair, DateTime time)
     : this(algorithm, keyPair.Public, keyPair.Private, time)
 {
 }
Exemplo n.º 38
0
 public PublicSubkeyPacket(PublicKeyAlgorithmTag algorithm, DateTime time, IBcpgKey key)
     : base(algorithm, time, key)
 {
 }
Exemplo n.º 39
0
 public PgpPublicKey(PublicKeyAlgorithmTag algorithm, AsymmetricKeyParameter pubKey, DateTime time);
Exemplo n.º 40
0
        public PgpPublicKey(PublicKeyAlgorithmTag algorithm, AsymmetricKeyParameter pubKey, global::System.DateTime time)
        {
            //IL_0044: Unknown result type (might be due to invalid IL or missing references)
            //IL_016b: Expected O, but got Unknown
            if (pubKey.IsPrivate)
            {
                throw new ArgumentException("Expected a public key", "pubKey");
            }
            IBcpgKey key;

            if (pubKey is RsaKeyParameters)
            {
                RsaKeyParameters rsaKeyParameters = (RsaKeyParameters)pubKey;
                key = new RsaPublicBcpgKey(rsaKeyParameters.Modulus, rsaKeyParameters.Exponent);
            }
            else if (pubKey is DsaPublicKeyParameters)
            {
                DsaPublicKeyParameters dsaPublicKeyParameters = (DsaPublicKeyParameters)pubKey;
                DsaParameters          parameters             = dsaPublicKeyParameters.Parameters;
                key = new DsaPublicBcpgKey(parameters.P, parameters.Q, parameters.G, dsaPublicKeyParameters.Y);
            }
            else if (pubKey is ECPublicKeyParameters)
            {
                ECPublicKeyParameters eCPublicKeyParameters = (ECPublicKeyParameters)pubKey;
                switch (algorithm)
                {
                case PublicKeyAlgorithmTag.EC:
                    key = new ECDHPublicBcpgKey(eCPublicKeyParameters.PublicKeyParamSet, eCPublicKeyParameters.Q, HashAlgorithmTag.Sha256, SymmetricKeyAlgorithmTag.Aes128);
                    break;

                case PublicKeyAlgorithmTag.ECDsa:
                    key = new ECDsaPublicBcpgKey(eCPublicKeyParameters.PublicKeyParamSet, eCPublicKeyParameters.Q);
                    break;

                default:
                    throw new PgpException("unknown EC algorithm");
                }
            }
            else
            {
                if (!(pubKey is ElGamalPublicKeyParameters))
                {
                    throw new PgpException("unknown key class");
                }
                ElGamalPublicKeyParameters elGamalPublicKeyParameters = (ElGamalPublicKeyParameters)pubKey;
                ElGamalParameters          parameters2 = elGamalPublicKeyParameters.Parameters;
                key = new ElGamalPublicBcpgKey(parameters2.P, parameters2.G, elGamalPublicKeyParameters.Y);
            }
            publicPk = new PublicKeyPacket(algorithm, time, key);
            ids      = Platform.CreateArrayList();
            idSigs   = Platform.CreateArrayList();
            try
            {
                Init();
            }
            catch (IOException val)
            {
                IOException exception = val;
                throw new PgpException("exception calculating keyId", (global::System.Exception)(object) exception);
            }
        }
 public PgpSignatureTypeIdentifier(PublicKeyAlgorithmTag keyAlgorithm, HashAlgorithmTag hashAlgorithm)
 {
     this.mKeyAlgorithm  = keyAlgorithm;
     this.mHashAlgorithm = hashAlgorithm;
 }
Exemplo n.º 42
0
 public SignaturePacket(int version, int signatureType, long keyId, PublicKeyAlgorithmTag keyAlgorithm, HashAlgorithmTag hashAlgorithm, long creationTime, byte[] fingerprint, MPInteger[] signature)
     : this(version, signatureType, keyId, keyAlgorithm, hashAlgorithm, null, null, fingerprint, signature)
 {
     this.creationTime = creationTime;
 }
Exemplo n.º 43
0
        void AddEncryptionKeyPair(PgpKeyRingGenerator keyRingGenerator, KeyGenerationParameters parameters, PublicKeyAlgorithmTag algorithm, DateTime now, long expirationTime, int[] encryptionAlgorithms, int[] digestAlgorithms)
        {
            var keyPairGenerator = GeneratorUtilities.GetKeyPairGenerator("RSA");

            keyPairGenerator.Init(parameters);

            var keyPair            = new PgpKeyPair(algorithm, keyPairGenerator.GenerateKeyPair(), now);
            var subpacketGenerator = new PgpSignatureSubpacketGenerator();

            subpacketGenerator.SetKeyFlags(false, PgpKeyFlags.CanEncryptCommunications | PgpKeyFlags.CanEncryptStorage);
            subpacketGenerator.SetPreferredSymmetricAlgorithms(false, encryptionAlgorithms);
            subpacketGenerator.SetPreferredHashAlgorithms(false, digestAlgorithms);

            if (expirationTime > 0)
            {
                subpacketGenerator.SetKeyExpirationTime(false, expirationTime);
                subpacketGenerator.SetSignatureExpirationTime(false, expirationTime);
            }

            keyRingGenerator.AddSubKey(keyPair, subpacketGenerator.Generate(), null);
        }
Exemplo n.º 44
0
 public PublicSubkeyPacket(PublicKeyAlgorithmTag algorithm, global::System.DateTime time, IBcpgKey key)
     : base(algorithm, time, key)
 {
 }
Exemplo n.º 45
0
        internal SignaturePacket(
            BcpgInputStream bcpgIn)
        {
            version = bcpgIn.ReadByte();

            if (version == 3 || version == 2)
            {
//                int l =
                bcpgIn.ReadByte();

                signatureType = bcpgIn.ReadByte();
                creationTime  = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16)
                                 | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000L;

                keyId |= (long)bcpgIn.ReadByte() << 56;
                keyId |= (long)bcpgIn.ReadByte() << 48;
                keyId |= (long)bcpgIn.ReadByte() << 40;
                keyId |= (long)bcpgIn.ReadByte() << 32;
                keyId |= (long)bcpgIn.ReadByte() << 24;
                keyId |= (long)bcpgIn.ReadByte() << 16;
                keyId |= (long)bcpgIn.ReadByte() << 8;
                keyId |= (uint)bcpgIn.ReadByte();

                keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
                hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
            }
            else if (version == 4)
            {
                signatureType = bcpgIn.ReadByte();
                keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
                hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();

                int    hashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                byte[] hashed       = new byte[hashedLength];

                bcpgIn.ReadFully(hashed);

                //
                // read the signature sub packet data.
                //
                SignatureSubpacketsParser sIn = new SignatureSubpacketsParser(
                    new MemoryStream(hashed, false));

                IList v = Platform.CreateArrayList();
                SignatureSubpacket sub;
                while ((sub = sIn.ReadPacket()) != null)
                {
                    v.Add(sub);
                }

                hashedData = new SignatureSubpacket[v.Count];

                for (int i = 0; i != hashedData.Length; i++)
                {
                    SignatureSubpacket p = (SignatureSubpacket)v[i];
                    if (p is IssuerKeyId)
                    {
                        keyId = ((IssuerKeyId)p).KeyId;
                    }
                    else if (p is SignatureCreationTime)
                    {
                        creationTime = DateTimeUtilities.DateTimeToUnixMs(
                            ((SignatureCreationTime)p).GetTime());
                    }

                    hashedData[i] = p;
                }

                int    unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                byte[] unhashed       = new byte[unhashedLength];

                bcpgIn.ReadFully(unhashed);

                sIn = new SignatureSubpacketsParser(new MemoryStream(unhashed, false));

                v.Clear();

                while ((sub = sIn.ReadPacket()) != null)
                {
                    v.Add(sub);
                }

                unhashedData = new SignatureSubpacket[v.Count];

                for (int i = 0; i != unhashedData.Length; i++)
                {
                    SignatureSubpacket p = (SignatureSubpacket)v[i];
                    if (p is IssuerKeyId)
                    {
                        keyId = ((IssuerKeyId)p).KeyId;
                    }

                    unhashedData[i] = p;
                }
            }
            else
            {
                throw new Exception("unsupported version: " + version);
            }

            fingerprint = new byte[2];
            bcpgIn.ReadFully(fingerprint);

            switch (keyAlgorithm)
            {
            case PublicKeyAlgorithmTag.RsaGeneral:
            case PublicKeyAlgorithmTag.RsaSign:
                MPInteger v = new MPInteger(bcpgIn);
                signature = new MPInteger[] { v };
                break;

            case PublicKeyAlgorithmTag.Dsa:
                MPInteger r = new MPInteger(bcpgIn);
                MPInteger s = new MPInteger(bcpgIn);
                signature = new MPInteger[] { r, s };
                break;

            case PublicKeyAlgorithmTag.ElGamalEncrypt:     // yep, this really does happen sometimes.
            case PublicKeyAlgorithmTag.ElGamalGeneral:
                MPInteger p = new MPInteger(bcpgIn);
                MPInteger g = new MPInteger(bcpgIn);
                MPInteger y = new MPInteger(bcpgIn);
                signature = new MPInteger[] { p, g, y };
                break;

            case PublicKeyAlgorithmTag.ECDsa:
                MPInteger ecR = new MPInteger(bcpgIn);
                MPInteger ecS = new MPInteger(bcpgIn);
                signature = new MPInteger[] { ecR, ecS };
                break;

            default:
                if (keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
                {
                    signature = null;
                    MemoryStream bOut = new MemoryStream();
                    int          ch;
                    while ((ch = bcpgIn.ReadByte()) >= 0)
                    {
                        bOut.WriteByte((byte)ch);
                    }
                    signatureEncoding = bOut.ToArray();
                }
                else
                {
                    throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
                }
                break;
            }
        }
Exemplo n.º 46
0
        /// <summary>
        /// Create a PgpPublicKey from the passed in lightweight one.
        /// </summary>
        /// <remarks>
        /// Note: the time passed in affects the value of the key's keyId, so you probably only want
        /// to do this once for a lightweight key, or make sure you keep track of the time you used.
        /// </remarks>
        /// <param name="algorithm">Asymmetric algorithm type representing the public key.</param>
        /// <param name="pubKey">Actual public key to associate.</param>
        /// <param name="time">Date of creation.</param>
        /// <exception cref="ArgumentException">If <c>pubKey</c> is not public.</exception>
        /// <exception cref="PgpException">On key creation problem.</exception>
        public PgpPublicKey(
            PublicKeyAlgorithmTag algorithm,
            AsymmetricKeyParameter pubKey,
            DateTime time)
        {
            if (pubKey.IsPrivate)
            {
                throw new ArgumentException("Expected a public key", "pubKey");
            }

            IBcpgKey bcpgKey;

            if (pubKey is RsaKeyParameters)
            {
                RsaKeyParameters rK = (RsaKeyParameters)pubKey;

                bcpgKey = new RsaPublicBcpgKey(rK.Modulus, rK.Exponent);
            }
            else if (pubKey is DsaPublicKeyParameters)
            {
                DsaPublicKeyParameters dK = (DsaPublicKeyParameters)pubKey;
                DsaParameters          dP = dK.Parameters;

                bcpgKey = new DsaPublicBcpgKey(dP.P, dP.Q, dP.G, dK.Y);
            }
            else if (pubKey is ECPublicKeyParameters)
            {
                ECPublicKeyParameters ecK = (ECPublicKeyParameters)pubKey;

                if (algorithm == PublicKeyAlgorithmTag.ECDH)
                {
                    bcpgKey = new ECDHPublicBcpgKey(ecK.PublicKeyParamSet, ecK.Q, HashAlgorithmTag.Sha256, SymmetricKeyAlgorithmTag.Aes128);
                }
                else if (algorithm == PublicKeyAlgorithmTag.ECDsa)
                {
                    bcpgKey = new ECDsaPublicBcpgKey(ecK.PublicKeyParamSet, ecK.Q);
                }
                else
                {
                    throw new PgpException("unknown EC algorithm");
                }
            }
            else if (pubKey is ElGamalPublicKeyParameters)
            {
                ElGamalPublicKeyParameters eK = (ElGamalPublicKeyParameters)pubKey;
                ElGamalParameters          eS = eK.Parameters;

                bcpgKey = new ElGamalPublicBcpgKey(eS.P, eS.G, eK.Y);
            }
            else
            {
                throw new PgpException("unknown key class");
            }

            this.publicPk = new PublicKeyPacket(algorithm, time, bcpgKey);
            this.ids      = Platform.CreateArrayList();
            this.idSigs   = Platform.CreateArrayList();

            try
            {
                Init();
            }
            catch (IOException e)
            {
                throw new PgpException("exception calculating keyId", e);
            }
        }
 /// <summary>
 /// Sets revocation key sub packet
 /// </summary>
 public void SetRevocationKey(bool isCritical, PublicKeyAlgorithmTag keyAlgorithm, byte[] fingerprint)
 {
     list.Add(new RevocationKey(isCritical, RevocationKeyTag.ClassDefault, keyAlgorithm, fingerprint));
 }
        /// <summary>
        /// Create master signing key.
        /// </summary>
        /// <param name="identity">
        /// Identity of the key.
        /// </param>
        /// <param name="password">
        /// Password to protect the secret key.
        /// </param>
        /// <param name="expires">
        /// Key expiry; null means never expires.
        /// </param>
        /// <param name="signKeyLength">
        /// Length of the signing key.
        /// </param>
        /// <param name="signGenerator">
        /// Generator for the signing key.
        /// </param>
        /// <param name="signingAlgorithm">
        /// Signing algorithm.
        /// </param>
        /// <param name="symmetricAlgorithm">
        /// Symmetric algorithm.
        /// </param>
        /// <returns>
        /// Returns the <see cref="PgpKeyRingGenerator"/> with the keyring properties
        /// thus far.
        /// </returns>
        public static PgpKeyRingGenerator CreateMasterSigningKey(
            string identity,
            string password,
            DateTime?expires,
            int signKeyLength    = 2048,
            string signGenerator = "RSA",
            PublicKeyAlgorithmTag signingAlgorithm      = PublicKeyAlgorithmTag.RsaSign,
            SymmetricKeyAlgorithmTag symmetricAlgorithm = SymmetricKeyAlgorithmTag.Aes256)
        {
            var keyringParameters = new KeyRingParameters(signKeyLength, signGenerator)
            {
                Password = password,
                Identity = identity,
                PrivateKeyEncryptionAlgorithm = symmetricAlgorithm,
                SymmetricAlgorithms           = new[]
                {
                    SymmetricKeyAlgorithmTag.Aes256,
                    SymmetricKeyAlgorithmTag.Aes192,
                    SymmetricKeyAlgorithmTag.Aes128
                },
                HashAlgorithms = new[]
                {
                    HashAlgorithmTag.Sha256,
                    HashAlgorithmTag.Sha1,
                    HashAlgorithmTag.Sha384,
                    HashAlgorithmTag.Sha512,
                    HashAlgorithmTag.Sha224,
                }
            };

            // master signing key
            var generator = GeneratorUtilities.GetKeyPairGenerator(signGenerator);

            generator.Init(keyringParameters.KeyParams);
            var masterKeyPair = new PgpKeyPair(signingAlgorithm, generator.GenerateKeyPair(), DateTime.UtcNow);

            Debug.WriteLine("Generated master key with ID " + masterKeyPair.KeyId.ToString("X"));

            var symmetricAlgorithms = (from a in keyringParameters.SymmetricAlgorithms
                                       select(int) a).ToArray();
            var hashAlgorithms = (from a in keyringParameters.HashAlgorithms
                                  select(int) a).ToArray();

            var masterSubpckGen = new PgpSignatureSubpacketGenerator();

            masterSubpckGen.SetKeyFlags(false, PgpKeyFlags.CanSign | PgpKeyFlags.CanCertify);
            masterSubpckGen.SetPreferredSymmetricAlgorithms(false, symmetricAlgorithms);
            masterSubpckGen.SetPreferredHashAlgorithms(false, hashAlgorithms);
            if (expires != null)
            {
                masterSubpckGen.SetKeyExpirationTime(false, (long)((DateTime)expires - DateTime.Now).TotalSeconds);
            }

            // keyring -- adding master key
            return(new PgpKeyRingGenerator(
                       PgpSignature.DefaultCertification,
                       masterKeyPair,
                       keyringParameters.Identity,
                       keyringParameters.PrivateKeyEncryptionAlgorithm,
                       keyringParameters.GetPassword(),
                       true,
                       masterSubpckGen.Generate(),
                       null,
                       new SecureRandom()));
        }
        /// <summary>
        /// Export the public/private keypair.
        /// </summary>
        /// <param name="secretPath">
        /// The secret output path.
        /// </param>
        /// <param name="publicPath">
        /// The public output path.
        /// </param>
        /// <param name="publicKey">
        /// The public key.
        /// </param>
        /// <param name="privateKey">
        /// The private key.
        /// </param>
        /// <param name="identity">
        /// The identity for the key.
        /// </param>
        /// <param name="passPhrase">
        /// The pass phrase for the secret key file.
        /// </param>
        /// <param name="creationDate">
        /// Date/time the key was created.
        /// </param>
        /// <param name="publicKeyAlgorithm">
        /// The public key algorithm.
        /// </param>
        /// <param name="symmetricAlgorithm">
        /// The symmetric key algorithm.
        /// </param>
        /// <param name="armor">
        /// Should the keys be written using ASCII armor?
        /// </param>
        /// <returns>
        /// The <see cref="PgpSecretKey"/>.
        /// </returns>
        public static PgpSecretKey ExportKeyPair(
            string secretPath,
            string publicPath,
            AsymmetricKeyParameter publicKey,
            AsymmetricKeyParameter privateKey,
            string identity,
            char[] passPhrase,
            DateTime creationDate,
            PublicKeyAlgorithmTag publicKeyAlgorithm    = PublicKeyAlgorithmTag.RsaGeneral,
            SymmetricKeyAlgorithmTag symmetricAlgorithm = SymmetricKeyAlgorithmTag.Aes256,
            bool armor = true)
        {
            var secretKey = new PgpSecretKey(
                PgpSignature.DefaultCertification,
                publicKeyAlgorithm,
                publicKey,
                privateKey,
                creationDate,
                identity,
                symmetricAlgorithm,
                passPhrase,
                null,
                null,
                new SecureRandom());

            if (secretPath != null)
            {
                using (var secretOut = (Stream) new FileInfo(secretPath).OpenWrite())
                {
                    var secretOutputStream = secretOut;
                    if (armor)
                    {
                        secretOutputStream = new ArmoredOutputStream(secretOut);
                    }

                    secretKey.Encode(secretOutputStream);
                    secretOutputStream.Flush();

                    if (armor)
                    {
                        secretOutputStream.Dispose();
                    }
                }
            }

            if (publicPath != null)
            {
                using (var publicOut = (Stream) new FileInfo(publicPath).OpenWrite())
                {
                    var publicOutputStream = publicOut;
                    if (armor)
                    {
                        publicOutputStream = new ArmoredOutputStream(publicOut);
                    }

                    var key = secretKey.PublicKey;
                    key.Encode(publicOutputStream);
                    publicOutputStream.Flush();

                    if (armor)
                    {
                        publicOutputStream.Dispose();
                    }
                }
            }

            return(secretKey);
        }
        private void doTestTextSigV3(
			PublicKeyAlgorithmTag	encAlgorithm,
			HashAlgorithmTag		hashAlgorithm,
			IPgpPublicKey			pubKey,
			IPgpPrivateKey			privKey,
			byte[]					data,
			byte[]					canonicalData)
        {
            PgpV3SignatureGenerator sGen = new PgpV3SignatureGenerator(encAlgorithm, HashAlgorithmTag.Sha1);
            MemoryStream bOut = new MemoryStream();
            MemoryStream testIn = new MemoryStream(data, false);

            sGen.InitSign(PgpSignature.CanonicalTextDocument, privKey);
            sGen.GenerateOnePassVersion(false).Encode(bOut);

            PgpLiteralDataGenerator lGen = new PgpLiteralDataGenerator();
            Stream lOut = lGen.Open(
                new UncloseableStream(bOut),
                PgpLiteralData.Text,
                "_CONSOLE",
                data.Length * 2,
                DateTime.UtcNow);

            int ch;
            while ((ch = testIn.ReadByte()) >= 0)
            {
                lOut.WriteByte((byte)ch);
                sGen.Update((byte)ch);
            }

            lOut.Write(data, 0, data.Length);
            sGen.Update(data);

            lGen.Close();

            PgpSignature sig = sGen.Generate();

            if (sig.CreationTime == DateTimeUtilities.UnixMsToDateTime(0))
            {
                Fail("creation time not set in v3 signature");
            }

            sig.Encode(bOut);

            verifySignature(bOut.ToArray(), hashAlgorithm, pubKey, canonicalData);
        }
Exemplo n.º 51
0
 public PgpKeyPair(PublicKeyAlgorithmTag algorithm, AsymmetricKeyParameter pubKey, AsymmetricKeyParameter privKey, DateTime time)
 {
     pub  = new PgpPublicKey(algorithm, pubKey, time);
     priv = new PgpPrivateKey(pub.KeyId, pub.PublicKeyPacket, privKey);
 }
 public PublicKeyEncSessionPacket(long keyId, PublicKeyAlgorithmTag algorithm, BigInteger[] data)
     : this(keyId, algorithm, data, null)
 {
 }
Exemplo n.º 53
0
 public PgpSecretKey(int certificationLevel, PublicKeyAlgorithmTag algorithm, AsymmetricKeyParameter pubKey, AsymmetricKeyParameter privKey, global::System.DateTime time, string id, SymmetricKeyAlgorithmTag encAlgorithm, char[] passPhrase, bool useSha1, PgpSignatureSubpacketVector hashedPackets, PgpSignatureSubpacketVector unhashedPackets, SecureRandom rand)
     : this(certificationLevel, new PgpKeyPair(algorithm, pubKey, privKey, time), id, encAlgorithm, passPhrase, useSha1, hashedPackets, unhashedPackets, rand)
 {
 }
        private byte[] generateV3BinarySig(
			IPgpPrivateKey			privKey,
			PublicKeyAlgorithmTag	encAlgorithm,
			HashAlgorithmTag		hashAlgorithm)
        {
            MemoryStream bOut = new MemoryStream();
            MemoryStream testIn = new MemoryStream(TEST_DATA, false);
            PgpV3SignatureGenerator sGen = new PgpV3SignatureGenerator(encAlgorithm, hashAlgorithm);

            sGen.InitSign(PgpSignature.BinaryDocument, privKey);
            sGen.GenerateOnePassVersion(false).Encode(bOut);

            PgpLiteralDataGenerator lGen = new PgpLiteralDataGenerator();
            Stream lOut = lGen.Open(
                new UncloseableStream(bOut),
                PgpLiteralData.Binary,
                "_CONSOLE",
                TEST_DATA.Length * 2,
                DateTime.UtcNow);

            int ch;
            while ((ch = testIn.ReadByte()) >= 0)
            {
                lOut.WriteByte((byte)ch);
                sGen.Update((byte)ch);
            }

            lOut.Write(TEST_DATA, 0, TEST_DATA.Length);
            sGen.Update(TEST_DATA);

            lGen.Close();

            sGen.Generate().Encode(bOut);

            return bOut.ToArray();
        }
Exemplo n.º 55
0
        internal SignaturePacket(BcpgInputStream bcpgIn)
        {
            _version = bcpgIn.ReadByte();


            //TODO: refactor
            switch (_version)
            {
            case 2:
            case 3:
                bcpgIn.ReadByte();
                _signatureType = bcpgIn.ReadByte();
                CreationTime   = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16)
                                  | ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000L;
                _keyId        |= (long)bcpgIn.ReadByte() << 56;
                _keyId        |= (long)bcpgIn.ReadByte() << 48;
                _keyId        |= (long)bcpgIn.ReadByte() << 40;
                _keyId        |= (long)bcpgIn.ReadByte() << 32;
                _keyId        |= (long)bcpgIn.ReadByte() << 24;
                _keyId        |= (long)bcpgIn.ReadByte() << 16;
                _keyId        |= (long)bcpgIn.ReadByte() << 8;
                _keyId        |= (uint)bcpgIn.ReadByte();
                _keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
                _hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();
                break;

            case 4:
            {
                _signatureType = bcpgIn.ReadByte();
                _keyAlgorithm  = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
                _hashAlgorithm = (HashAlgorithmTag)bcpgIn.ReadByte();

                var hashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                var hashed       = new byte[hashedLength];

                bcpgIn.ReadFully(hashed);

                //
                // read the signature sub packet data.
                //
                using (var hashedStream = new MemoryStream(hashed, false))
                {
                    var sIn = new SignatureSubpacketsParser(hashedStream);
                    var v   = Platform.CreateArrayList <ISignatureSubpacket>();

                    SignatureSubpacket sub;
                    while ((sub = sIn.ReadPacket()) != null)
                    {
                        v.Add(sub);

                        var issuerKeyId = sub as IssuerKeyId;
                        if (issuerKeyId != null)
                        {
                            _keyId = issuerKeyId.KeyId;
                        }
                        else
                        {
                            var signatureCreationTime = sub as SignatureCreationTime;
                            if (signatureCreationTime != null)
                            {
                                CreationTime = DateTimeUtilities.DateTimeToUnixMs(signatureCreationTime.GetTime());
                            }
                        }
                    }
                    _hashedData = v.ToArray();

                    var unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
                    var unhashed       = new byte[unhashedLength];
                    bcpgIn.ReadFully(unhashed);

                    v.Clear();
                    using (var unhashedStream = new MemoryStream(unhashed, false))
                    {
                        sIn = new SignatureSubpacketsParser(unhashedStream);

                        while ((sub = sIn.ReadPacket()) != null)
                        {
                            v.Add(sub);

                            var issuerKeyId = sub as IssuerKeyId;
                            if (issuerKeyId != null)
                            {
                                _keyId = issuerKeyId.KeyId;
                            }
                        }
                    }
                    _unhashedData = v.ToArray();
                }
            }
            break;

            default:
                throw new Exception("unsupported version: " + _version);
            }

            _fingerprint = new byte[2];
            bcpgIn.ReadFully(_fingerprint);

            switch (_keyAlgorithm)
            {
            case PublicKeyAlgorithmTag.RsaGeneral:
            case PublicKeyAlgorithmTag.RsaSign:
                var v = new MPInteger(bcpgIn);
                _signature = new[] { v };
                break;

            case PublicKeyAlgorithmTag.Dsa:
            case PublicKeyAlgorithmTag.Ecdsa:
            case PublicKeyAlgorithmTag.Ecdh:
                var r = new MPInteger(bcpgIn);
                var s = new MPInteger(bcpgIn);
                _signature = new[] { r, s };
                break;

            case PublicKeyAlgorithmTag.ElGamalEncrypt:     // yep, this really does happen sometimes.
            case PublicKeyAlgorithmTag.ElGamalGeneral:
                var p = new MPInteger(bcpgIn);
                var g = new MPInteger(bcpgIn);
                var y = new MPInteger(bcpgIn);
                _signature = new[] { p, g, y };
                break;

            default:
                if (_keyAlgorithm >= PublicKeyAlgorithmTag.Experimental_1 && _keyAlgorithm <= PublicKeyAlgorithmTag.Experimental_11)
                {
                    _signature = null;
                    using (var bOut = new MemoryStream())
                    {
                        int ch;
                        while ((ch = bcpgIn.ReadByte()) >= 0)
                        {
                            bOut.WriteByte((byte)ch);
                        }
                        _signatureEncoding = bOut.ToArray();
                    }
                }
                else
                {
                    throw new IOException("unknown signature key algorithm: " + _keyAlgorithm);
                }
                break;
            }
        }