Example #1
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);
            }
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }