当前位置: 首页>>代码示例>>C#>>正文


C# OpenPgp.PgpPublicKey类代码示例

本文整理汇总了C#中Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKey的典型用法代码示例。如果您正苦于以下问题:C# PgpPublicKey类的具体用法?C# PgpPublicKey怎么用?C# PgpPublicKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PgpPublicKey类属于Org.BouncyCastle.Bcpg.OpenPgp命名空间,在下文中一共展示了PgpPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenPgpDigitalCertificate

		internal OpenPgpDigitalCertificate (PgpPublicKey pubkey)
		{
			var data = pubkey.GetFingerprint ();
			var builder = new StringBuilder ();

			for (int i = 0; i < data.Length; i++)
				builder.Append (data[i].ToString ("X"));

//			var trust = pubkey.GetTrustData ();
//			if (trust != null) {
//				TrustLevel = (TrustLevel) (trust[0] & 15);
//			} else {
//				TrustLevel = TrustLevel.None;
//			}

			Fingerprint = builder.ToString ();
			PublicKey = pubkey;

			foreach (string userId in pubkey.GetUserIds ()) {
				data = Encoding.UTF8.GetBytes (userId);
				MailboxAddress mailbox;
				int index = 0;

				if (!MailboxAddress.TryParse (ParserOptions.Default, data, ref index, data.Length, false, out mailbox))
					continue;

				Email = mailbox.Address;
				Name = mailbox.Name;
				break;
			}
		}
开发者ID:dcga,项目名称:MimeKit,代码行数:31,代码来源:OpenPgpDigitalCertificate.cs

示例2: PgpKeyPair

		/// <summary>Create a key pair from a PgpPrivateKey and a PgpPublicKey.</summary>
		/// <param name="pub">The public key.</param>
		/// <param name="priv">The private key.</param>
        public PgpKeyPair(
            PgpPublicKey	pub,
            PgpPrivateKey	priv)
        {
            this.pub = pub;
            this.priv = priv;
        }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:10,代码来源:PgpKeyPair.cs

示例3: InsertPublicKey

        /// <summary>
        /// Returns a new key ring with the public key passed in either added or
        /// replacing an existing one.
        /// </summary>
        /// <param name="pubRing">The public key ring to be modified.</param>
        /// <param name="pubKey">The public key to be inserted.</param>
        /// <returns>A new <c>PgpPublicKeyRing</c></returns>
        public static PgpPublicKeyRing InsertPublicKey(
            PgpPublicKeyRing	pubRing,
            PgpPublicKey		pubKey)
        {
            ArrayList keys = new ArrayList(pubRing.keys);
            bool found = false;

            for (int i = 0; i != keys.Count; i++)
            {
                PgpPublicKey key = (PgpPublicKey) keys[i];

                if (key.KeyId == pubKey.KeyId)
                {
                    found = true;
                    keys[i] = pubKey;
                }
            }

            if (!found)
            {
                keys.Add(pubKey);
            }

            return new PgpPublicKeyRing(keys);
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:32,代码来源:PgpPublicKeyRing.cs

示例4: PgpSecretKey

 internal PgpSecretKey(
     SecretKeyPacket	secret,
     PgpPublicKey	pub)
 {
     this.secret = secret;
     this.pub = pub;
 }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:7,代码来源:PgpSecretKey.cs

示例5: PgpKeyPair

		public PgpKeyPair(
            PublicKeyAlgorithmTag	algorithm,
            AsymmetricKeyParameter	pubKey,
            AsymmetricKeyParameter	privKey,
            DateTime				time)
        {
            this.pub = new PgpPublicKey(algorithm, pubKey, time);
			this.priv = new PgpPrivateKey(privKey, pub.KeyId);
        }
开发者ID:htlp,项目名称:itextsharp,代码行数:9,代码来源:PgpKeyPair.cs

示例6: PgpSecretKey

		internal PgpSecretKey(
			PgpPrivateKey				privKey,
			PgpPublicKey				pubKey,
			SymmetricKeyAlgorithmTag	encAlgorithm,
			char[]						passPhrase,
			bool						useSha1,
			SecureRandom				rand)
			: this(privKey, pubKey, encAlgorithm, passPhrase, useSha1, rand, false)
		{
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:10,代码来源:PgpSecretKey.cs

示例7: Load

        private void Load(PgpPublicKey key)
        {
            this.KeyId = key.KeyId.ToString("X");
            if (this.KeyId != null && this.KeyId.Length >= 15)
            {
                this.KeyIdShort = this.KeyId.Substring(this.KeyId.Length - 8);
            }
            this.Algorithm = key.Algorithm.ToString();
            this.BitStrength = key.BitStrength;
            this.IsMasterKey = key.IsMasterKey;
            this.IsEncryptionKey = key.IsEncryptionKey;
            this.Version = key.Version;
            this.CreatedOnUtc = key.CreationTime.ToUniversalTime();

            var validForSeconds = key.GetValidSeconds();
            if(validForSeconds > 0)
            {
                this.Expires = this.CreatedOnUtc.Value.AddSeconds(validForSeconds);
            }

            //this.ValidDays = key.ValidDays;
            //if (this.ValidDays.HasValue)
            //{
            //    this.Expires = this.CreatedOnUtc.Value.AddDays(this.ValidDays.Value);
            //}
            //else
            //{
            //    this.Expires = null;
            //}

            try
            {
                var userIds = key.GetUserIds();
                if (userIds != null)
                {
                    var enumerator = userIds.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        var userIdentity = enumerator.Current as string;
                        if (userIdentity != null && userIdentity.Contains("<") && userIdentity.Contains(">"))
                        {
                            var name = userIdentity.Substring(0, userIdentity.IndexOf("<") - 1).Trim();
                            this.IdentityName = name;
                            var email = userIdentity.Substring(userIdentity.IndexOf("<") + 1);
                            email = email.Substring(0, email.IndexOf(">")).Trim();
                            this.IdentityEmail = email;
                        }
                    }
                }
            }
            catch { }

        }
开发者ID:compliashield,项目名称:compliashield-sdk-encryption,代码行数:53,代码来源:PgpPublicKeyMetaData.cs

示例8: IsSigningAlg

		public bool IsSigningAlg(PgpPublicKey key)
		{
			var alg = key.Algorithm;
			switch (alg)
			{
				case PublicKeyAlgorithmTag.Dsa:
				case PublicKeyAlgorithmTag.RsaSign:
				case PublicKeyAlgorithmTag.ECDsa:
					return true;
			}

			return true;
		}
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:13,代码来源:PgpCrypto.cs

示例9: PgpEncrypt

    public static Stream PgpEncrypt(this Stream toEncrypt, PgpPublicKey encryptionKey, bool armor = true, bool verify = false)
    {
        var outStream = new MemoryStream();

        var encryptor = new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Cast5, verify, new SecureRandom());
        var literalizer = new PgpLiteralDataGenerator();
        var compressor = new PgpCompressedDataGenerator(CompressionAlgorithmTag.Zip);

        encryptor.AddMethod(encryptionKey);

        //it would be nice if these streams were read/write, and supported seeking.  Since they are not,
        //we need to shunt the data to a read/write stream so that we can control the flow of data as we go.

        using (var stream = new MemoryStream()) // this is the read/write stream
        using (var armoredStream = armor ? new ArmoredOutputStream(stream) : stream as Stream)
        using (var compressedStream = compressor.Open(armoredStream))
        {
            //data is encrypted first, then compressed, but because of the one-way nature of these streams,
            //other "interim" streams are required.  The raw data is encapsulated in a "Literal" PGP object.
            var rawData = toEncrypt.ReadFully();
            var buffer = new byte[1024];

            using (var literalOut = new MemoryStream())
            using (var literalStream = literalizer.Open(literalOut, PgpLiteralData.Binary, "STREAM", DateTime.UtcNow, buffer))
            {
                literalStream.Write(rawData, 0, rawData.Length);
                literalStream.Close();
                var literalData = literalOut.ReadFully();

                //The literal data object is then encrypted, which flows into the compressing stream and
                //(optionally) into the ASCII armoring stream.
                using (var encryptedStream = encryptor.Open(compressedStream, literalData.Length))
                {
                    encryptedStream.Write(literalData, 0, literalData.Length);
                    encryptedStream.Close();
                    compressedStream.Close();
                    armoredStream.Close();

                    //the stream processes are now complete, and our read/write stream is now populated with
                    //encrypted data.  Convert the stream to a byte array and write to the out stream.
                    stream.Position = 0;
                    var data = stream.ReadFully();
                    outStream.Write(data, 0, data.Length);
                }
            }
        }

        outStream.Position = 0;

        return outStream;
    }
开发者ID:CertiPay,项目名称:CertiPay.Common.Encryption,代码行数:51,代码来源:PGPUtilities.cs

示例10: IsEncryptionAlg

		public bool IsEncryptionAlg(PgpPublicKey key)
		{
			var alg = key.Algorithm;
			switch (alg)
			{
				case PublicKeyAlgorithmTag.DiffieHellman:
				case PublicKeyAlgorithmTag.EC:
				case PublicKeyAlgorithmTag.ElGamalEncrypt:
				case PublicKeyAlgorithmTag.RsaEncrypt:
					return true;
			}

			return false;
		}
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:14,代码来源:PgpCrypto.cs

示例11: PgpSecretKey

        public PgpSecretKey(
			int							certificationLevel,
			PgpKeyPair					keyPair,
			string						id,
			SymmetricKeyAlgorithmTag	encAlgorithm,
			char[]						passPhrase,
			bool						useSHA1,
			PgpSignatureSubpacketVector	hashedPackets,
			PgpSignatureSubpacketVector	unhashedPackets,
			SecureRandom				rand)
            : this(keyPair, encAlgorithm, passPhrase, useSHA1, rand)
        {
            try
            {
                this.trust = null;
                this.ids = new ArrayList();
                ids.Add(id);

                this.idTrusts = new ArrayList();
                idTrusts.Add(null);

                this.idSigs = new ArrayList();

                PgpSignatureGenerator sGen = new PgpSignatureGenerator(
                    keyPair.PublicKey.Algorithm, HashAlgorithmTag.Sha1);

                //
                // Generate the certification
                //
                sGen.InitSign(certificationLevel, keyPair.PrivateKey);

                sGen.SetHashedSubpackets(hashedPackets);
                sGen.SetUnhashedSubpackets(unhashedPackets);

                PgpSignature certification = sGen.GenerateCertification(id, keyPair.PublicKey);
                this.pub = PgpPublicKey.AddCertification(keyPair.PublicKey, id, certification);

                ArrayList sigList = new ArrayList();
                sigList.Add(certification);
                idSigs.Add(sigList);
            }
            catch (PgpException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new PgpException("Exception encrypting key", e);
            }
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:50,代码来源:PgpSecretKey.cs

示例12: EncryptFile

        private static void EncryptFile(Stream outputStream, string fileName, PgpPublicKey encKey, bool armor, bool withIntegrityCheck)
        {
            if (armor)
                outputStream = new ArmoredOutputStream(outputStream);

            try
            {
                MemoryStream bOut = new MemoryStream();
                PgpCompressedDataGenerator comData = new PgpCompressedDataGenerator(
                CompressionAlgorithmTag.Zip);
                PgpUtilities.WriteFileToLiteralData(
                comData.Open(bOut),
                PgpLiteralData.Binary,
                new FileInfo(fileName));
                comData.Close();
                PgpEncryptedDataGenerator cPk = new PgpEncryptedDataGenerator(
                SymmetricKeyAlgorithmTag.Cast5, withIntegrityCheck, new SecureRandom());
                cPk.AddMethod(encKey);
                byte[] bytes = bOut.ToArray();
                Stream cOut = cPk.Open(outputStream, bytes.Length);
                cOut.Write(bytes, 0, bytes.Length);
                cOut.Close();
                if (armor)
                    outputStream.Close();
            }

            catch (PgpException e)
            {

                Console.Error.WriteLine(e);
                Exception underlyingException = e.InnerException;
                if (underlyingException != null)
                {

                    Console.Error.WriteLine(underlyingException.Message);
                    Console.Error.WriteLine(underlyingException.StackTrace);

                }
            }
        }
开发者ID:ojoadeolagabriel,项目名称:TqWorkflow-beta,代码行数:40,代码来源:AutoPayLoginHandler.cs

示例13: InitVerify

		/// <summary>Initialise the signature object for verification.</summary>
        public void InitVerify(
            PgpPublicKey pubKey)
        {
			lastb = 0;

			try
			{
				sig = SignerUtilities.GetSigner(
					PgpUtilities.GetSignatureName(sigPack.KeyAlgorithm, sigPack.HashAlgorithm));
			}
			catch (Exception e)
			{
				throw new PgpException("can't set up signature object.",  e);
			}

			try
            {
                sig.Init(false, pubKey.GetKey());
            }
			catch (InvalidKeyException e)
            {
                throw new PgpException("invalid key.", e);
            }
        }
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:25,代码来源:PgpOnePassSignature.cs

示例14: UpdateWithPublicKey

		private void UpdateWithPublicKey(
			PgpPublicKey key)
		{
			byte[] keyBytes = GetEncodedPublicKey(key);

			this.Update(
				(byte) 0x99,
				(byte)(keyBytes.Length >> 8),
				(byte)(keyBytes.Length));
			this.Update(keyBytes);
		}
开发者ID:htlp,项目名称:itextsharp,代码行数:11,代码来源:PgpSignature.cs

示例15: InitVerify

		public void InitVerify(
            PgpPublicKey pubKey)
        {
			lastb = 0;
            if (sig == null)
            {
                GetSig();
            }
            try
            {
                sig.Init(false, pubKey.GetKey());
            }
            catch (InvalidKeyException e)
            {
                throw new PgpException("invalid key.", e);
            }
        }
开发者ID:htlp,项目名称:itextsharp,代码行数:17,代码来源:PgpSignature.cs


注:本文中的Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。