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


C# Parameters.RsaKeyParameters类代码示例

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


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

示例1: TestRsaDigestSigner

        public void TestRsaDigestSigner()
        {
            BigInteger rsaPubMod = new BigInteger(Base64.Decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt"));
            BigInteger rsaPubExp = new BigInteger(Base64.Decode("EQ=="));
            BigInteger rsaPrivMod = new BigInteger(Base64.Decode("AIASoe2PQb1IP7bTyC9usjHP7FvnUMVpKW49iuFtrw/dMpYlsMMoIU2jupfifDpdFxIktSB4P+6Ymg5WjvHKTIrvQ7SR4zV4jaPTu56Ys0pZ9EDA6gb3HLjtU+8Bb1mfWM+yjKxcPDuFjwEtjGlPHg1Vq+CA9HNcMSKNn2+tW6qt"));
            BigInteger rsaPrivDP = new BigInteger(Base64.Decode("JXzfzG5v+HtLJIZqYMUefJfFLu8DPuJGaLD6lI3cZ0babWZ/oPGoJa5iHpX4Ul/7l3s1PFsuy1GhzCdOdlfRcQ=="));
            BigInteger rsaPrivDQ = new BigInteger(Base64.Decode("YNdJhw3cn0gBoVmMIFRZzflPDNthBiWy/dUMSRfJCxoZjSnr1gysZHK01HteV1YYNGcwPdr3j4FbOfri5c6DUQ=="));
            BigInteger rsaPrivExp = new BigInteger(Base64.Decode("DxFAOhDajr00rBjqX+7nyZ/9sHWRCCp9WEN5wCsFiWVRPtdB+NeLcou7mWXwf1Y+8xNgmmh//fPV45G2dsyBeZbXeJwB7bzx9NMEAfedchyOwjR8PYdjK3NpTLKtZlEJ6Jkh4QihrXpZMO4fKZWUm9bid3+lmiq43FwW+Hof8/E="));
            BigInteger rsaPrivP = new BigInteger(Base64.Decode("AJ9StyTVW+AL/1s7RBtFwZGFBgd3zctBqzzwKPda6LbtIFDznmwDCqAlIQH9X14X7UPLokCDhuAa76OnDXb1OiE="));
            BigInteger rsaPrivQ = new BigInteger(Base64.Decode("AM3JfD79dNJ5A3beScSzPtWxx/tSLi0QHFtkuhtSizeXdkv5FSba7lVzwEOGKHmW829bRoNxThDy4ds1IihW1w0="));
            BigInteger rsaPrivQinv = new BigInteger(Base64.Decode("Lt0g7wrsNsQxuDdB8q/rH8fSFeBXMGLtCIqfOec1j7FEIuYA/ACiRDgXkHa0WgN7nLXSjHoy630wC5Toq8vvUg=="));
            RsaKeyParameters rsaPublic = new RsaKeyParameters(false, rsaPubMod, rsaPubExp);
			RsaPrivateCrtKeyParameters rsaPrivate = new RsaPrivateCrtKeyParameters(rsaPrivMod, rsaPubExp, rsaPrivExp, rsaPrivP, rsaPrivQ, rsaPrivDP, rsaPrivDQ, rsaPrivQinv);

            byte[] msg = new byte[] { 1, 6, 3, 32, 7, 43, 2, 5, 7, 78, 4, 23 };

            RsaDigestSigner signer = new RsaDigestSigner(new Sha1Digest());
            signer.Init(true, rsaPrivate);
            signer.BlockUpdate(msg, 0, msg.Length);
            byte[] sig = signer.GenerateSignature();

            signer.Init(false,rsaPublic);
            signer.BlockUpdate(msg, 0, msg.Length);
            Assert.IsTrue(signer.VerifySignature(sig), "RSA IDigest Signer failed.");
        }
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:25,代码来源:TestCertificateGen.cs

示例2: GenerateEncryptedPreMasterSecret

		public static byte[] GenerateEncryptedPreMasterSecret(SecureRandom random,
			RsaKeyParameters rsaServerPublicKey, Stream output)
		{
			/*
			 * Choose a PremasterSecret and send it encrypted to the server
			 */
			byte[] premasterSecret = new byte[48];
			random.NextBytes(premasterSecret);
			TlsUtilities.WriteVersion(premasterSecret, 0);

			Pkcs1Encoding encoding = new Pkcs1Encoding(new RsaBlindedEngine());
			encoding.Init(true, new ParametersWithRandom(rsaServerPublicKey, random));

			try
			{
				byte[] keData = encoding.ProcessBlock(premasterSecret, 0, premasterSecret.Length);
                TlsUtilities.WriteOpaque16(keData, output);
			}
			catch (InvalidCipherTextException)
			{
				/*
				* This should never happen, only during decryption.
				*/
				throw new TlsFatalAlert(AlertDescription.internal_error);
			}

			return premasterSecret;
		}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:28,代码来源:TlsRsaUtilities.cs

示例3: GetRsaKeyPair

        public AsymmetricCipherKeyPair GetRsaKeyPair(
			RSACryptoServiceProvider rsaCsp)
        {
            RSAParameters rp = rsaCsp.ExportParameters(true);

            BigInteger modulus = new BigInteger(1, rp.Modulus);
            BigInteger pubExp = new BigInteger(1, rp.Exponent);

            RsaKeyParameters pubKey = new RsaKeyParameters(
                false,
                modulus,
                pubExp);

            RsaPrivateCrtKeyParameters privKey = new RsaPrivateCrtKeyParameters(
                modulus,
                pubExp,
                new BigInteger(1, rp.D),
                new BigInteger(1, rp.P),
                new BigInteger(1, rp.Q),
                new BigInteger(1, rp.DP),
                new BigInteger(1, rp.DQ),
                new BigInteger(1, rp.InverseQ));

            return new AsymmetricCipherKeyPair(pubKey, privKey);
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:25,代码来源:DotNetUtilities.cs

示例4: ProcessServerCertificate

        public override void ProcessServerCertificate(Certificate serverCertificate)
        {
            if (serverCertificate.IsEmpty)
                throw new TlsFatalAlert(AlertDescription.bad_certificate);

            X509CertificateStructure x509Cert = serverCertificate.GetCertificateAt(0);

            SubjectPublicKeyInfo keyInfo = x509Cert.SubjectPublicKeyInfo;
            try
            {
                this.mServerPublicKey = PublicKeyFactory.CreateKey(keyInfo);
            }
            catch (Exception e)
            {
                throw new TlsFatalAlert(AlertDescription.unsupported_certificate, e);
            }

            // Sanity check the PublicKeyFactory
            if (this.mServerPublicKey.IsPrivate)
                throw new TlsFatalAlert(AlertDescription.internal_error);

            this.mRsaServerPublicKey = ValidateRsaPublicKey((RsaKeyParameters)this.mServerPublicKey);

            TlsUtilities.ValidateKeyUsage(x509Cert, KeyUsage.KeyEncipherment);

            base.ProcessServerCertificate(serverCertificate);
        }
开发者ID:ubberkid,项目名称:PeerATT,代码行数:27,代码来源:TlsRsaKeyExchange.cs

示例5: ProcessServerCertificate

        public virtual void ProcessServerCertificate(Certificate serverCertificate)
        {
            X509CertificateStructure x509Cert = serverCertificate.certs[0];
            SubjectPublicKeyInfo keyInfo = x509Cert.SubjectPublicKeyInfo;

            try
            {
                this.serverPublicKey = PublicKeyFactory.CreateKey(keyInfo);
            }
            //			catch (RuntimeException)
            catch (Exception)
            {
                throw new TlsFatalAlert(AlertDescription.unsupported_certificate);
            }

            // Sanity check the PublicKeyFactory
            if (this.serverPublicKey.IsPrivate)
            {
                throw new TlsFatalAlert(AlertDescription.internal_error);
            }

            this.rsaServerPublicKey = ValidateRsaPublicKey((RsaKeyParameters)this.serverPublicKey);

            TlsUtilities.ValidateKeyUsage(x509Cert, KeyUsage.KeyEncipherment);

            // TODO
            /*
            * Perform various checks per RFC2246 7.4.2: "Unless otherwise specified, the
            * signing algorithm for the certificate must be the same as the algorithm for the
            * certificate key."
            */
        }
开发者ID:jomamorales,项目名称:createPDF,代码行数:32,代码来源:TlsRsaKeyExchange.cs

示例6: getCades

        /// <summary>
        /// Genera la firma CADES
        /// </summary>
        /// <param name="data">Datos a firmar</param>
        /// <param name="privateKey">Clave privada usada para la firma</param>
        /// <param name="certificado">Certificado del firmante</param>
        /// <param name="algo">Algoritmo de firma</param>
        /// <param name="format">Formato de firma</param>
        /// <returns>Firma en formato binario</returns>
        public static byte[] getCades(byte[] data,
            RsaKeyParameters privateKey,
            byte[] certificado,
            string algo,
            string format)
        {
            GenCAdESEPESSignedData prueba = new GenCAdESEPESSignedData();
            Dictionary<string, string> p1 = new Dictionary<string, string>();
            p1.Add("format", format);
            p1.Add("mode", "implicit");
            p1.Add("policyIdentifier", null);
            p1.Add("policyIdentifierHash", null);
            p1.Add("policyIdentifierHashAlgorithm", null);
            p1.Add("policyQualifier", null);
            p1.Add("signingCertificateV2", "false");

            AdESPolicy politica = new AdESPolicy(p1);

            X509Certificate2 cert = new X509Certificate2();
            cert.SetRawCertData(certificado);
            cert.SetKey(privateKey);

            X509Certificate2[] certs = new X509Certificate2[1];
            certs[0] = cert;

            AOCAdESSigner cadesSigner = new AOCAdESSigner();
            byte[] datos = cadesSigner.sign(data, algo, certs, p1);

            return datos;
        }
开发者ID:bibou1324,项目名称:clienteafirma,代码行数:39,代码来源:CriptoManager.cs

示例7: BigIntegerRSAPublicKey

 public BigIntegerRSAPublicKey(RsaKeyParameters rsaKeyParameters)
 {
     Debug.Assert(rsaKeyParameters != null);
     this.Modulus = rsaKeyParameters.Modulus;
     this.modulusAsString = rsaKeyParameters.Modulus.ToString(10);
     this.Exponent = rsaKeyParameters.Exponent;
     this.exponentAsString = rsaKeyParameters.Exponent.ToString(10);
 }
开发者ID:ricardoshimoda,项目名称:thali,代码行数:8,代码来源:BigIntegerRSAPublicKey.cs

示例8: InitializeRSA

        private void InitializeRSA()
        {
            string[] keyComponents = publicKey.Split('|');
            var modulus = new Org.BouncyCastle.Math.BigInteger(keyComponents[1].ToLower(), 16);
            var exponent = new Org.BouncyCastle.Math.BigInteger(keyComponents[0].ToLower(), 16);
            RsaKeyParameters keyParams = new RsaKeyParameters(false, modulus, exponent);

            rsaCipher = CipherUtilities.GetCipher("RSA/None/PKCS1Padding");
            rsaCipher.Init(true, keyParams);
        }
开发者ID:gbarillot,项目名称:client-side-encryption,代码行数:10,代码来源:Encrypter.cs

示例9: RsaBlindingParameters

        public RsaBlindingParameters(
			RsaKeyParameters	publicKey,
			IBigInteger			blindingFactor)
        {
            if (publicKey.IsPrivate)
                throw new ArgumentException("RSA parameters should be for a public key");

            this.publicKey = publicKey;
            this.blindingFactor = blindingFactor;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:10,代码来源:RSABlindingParameters.cs

示例10: Key

        public Key(string pem)
        {
            var k = new CertificateLoader().LoadFirst<AsymmetricCipherKeyPair>("key", pem);
            _rsaKey = k.Private as RsaPrivateCrtKeyParameters;

            if (_rsaKey == null)
                throw new SecularException("Cannot find key in PEM string.");

            var rsaKeyParameters = new RsaKeyParameters(false, _rsaKey.Modulus, _rsaKey.PublicExponent);
            PublicKey = new PublicKey(rsaKeyParameters);
        }
开发者ID:bitdiff,项目名称:secular,代码行数:11,代码来源:Key.cs

示例11: doTestStrictPkcs1Length

		private void doTestStrictPkcs1Length(RsaKeyParameters pubParameters, RsaKeyParameters privParameters)
		{
			IAsymmetricBlockCipher eng = new RsaBlindedEngine();

			eng.Init(true, privParameters);

			byte[] data = null;

			try
			{
				data = eng.ProcessBlock(oversizedSig, 0, oversizedSig.Length);
			}
			catch (Exception e)
			{
				Fail("RSA: failed - exception " + e.ToString(), e);
			}

			eng = new Pkcs1Encoding(eng);

			eng.Init(false, pubParameters);

			try
			{
				data = eng.ProcessBlock(data, 0, data.Length);

				Fail("oversized signature block not recognised");
			}
			catch (InvalidCipherTextException e)
			{
				if (!e.Message.Equals("block incorrect size"))
				{
					Fail("RSA: failed - exception " + e.ToString(), e);
				}
			}


			// Create the encoding with StrictLengthEnabled=false (done thru environment in Java version)
			Pkcs1Encoding.StrictLengthEnabled = false;

			eng = new Pkcs1Encoding(new RsaBlindedEngine());

			eng.Init(false, pubParameters);

			try
			{
				data = eng.ProcessBlock(data, 0, data.Length);
			}
			catch (InvalidCipherTextException e)
			{
				Fail("RSA: failed - exception " + e.ToString(), e);
			}

			Pkcs1Encoding.StrictLengthEnabled = true;
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:54,代码来源:RSABlindedTest.cs

示例12: Init

		/**
		* initialise the RSA engine.
		*
		* @param forEncryption true if we are encrypting, false otherwise.
		* @param param the necessary RSA key parameters.
		*/
        public virtual void Init(
			bool				forEncryption,
			ICipherParameters	parameters)
		{
			if (parameters is ParametersWithRandom)
			{
				parameters = ((ParametersWithRandom) parameters).Parameters;
			}

			if (!(parameters is RsaKeyParameters))
				throw new InvalidKeyException("Not an RSA key");

			this.key = (RsaKeyParameters) parameters;
			this.forEncryption = forEncryption;
			this.bitSize = key.Modulus.BitLength;
		}
开发者ID:KimikoMuffin,项目名称:bc-csharp,代码行数:22,代码来源:RSACoreEngine.cs

示例13: Rsa

        static Rsa()
        {
            var openTibiaDecryptKey = new RsaPrivateCrtKeyParameters(new BigInteger(Constants.RSAKey.OpenTibiaM), new BigInteger(Constants.RSAKey.OpenTibiaE),
                new BigInteger(Constants.RSAKey.OpenTibiaE), new BigInteger(Constants.RSAKey.OpenTibiaP), new BigInteger(Constants.RSAKey.OpenTibiaQ),
                new BigInteger(Constants.RSAKey.OpenTibiaDP), new BigInteger(Constants.RSAKey.OpenTibiaDQ), new BigInteger(Constants.RSAKey.OpenTibiaInverseQ));

            openTibiaDecryptEngine = new RsaEngine();
            openTibiaDecryptEngine.Init(false, openTibiaDecryptKey);

            var realTibiaEncryptKey = new RsaKeyParameters(false, new BigInteger(Constants.RSAKey.RealTibiaM), new BigInteger(Constants.RSAKey.RealTibiaE));
            realTibiaEncryptEngine = new RsaEngine();
            realTibiaEncryptEngine.Init(true, realTibiaEncryptKey);

            var openTibiaEncryptKey = new RsaKeyParameters(false, new BigInteger(Constants.RSAKey.OpenTibiaM), new BigInteger(Constants.RSAKey.OpenTibiaE));
            openTibiaEncryptEngine = new RsaEngine();
            openTibiaEncryptEngine.Init(true, openTibiaEncryptKey);
        }
开发者ID:sridhar19091986,项目名称:sharpmaptracker,代码行数:17,代码来源:Rsa.cs

示例14: Init

        public static byte[] Init()
        {
            AsymmetricCipherKeyPair keyPair = null;

            string path = "proxy/session-key";
            try
            {
                AsymmetricKeyParameter keyPub = PublicKeyFactory.CreateKey(File.ReadAllBytes(path + ".pub"));
                AsymmetricKeyParameter KeyPriv = PrivateKeyFactory.CreateKey(File.ReadAllBytes(path + ".priv"));
                keyPair = new AsymmetricCipherKeyPair(keyPub, KeyPriv);
                Debug.WriteLine("Loaded session.key");
            } catch (Exception e)
            {
                Log.WriteServer(e);

                Debug.WriteLine("Generating session.key...");
                var generator = new RsaKeyPairGenerator();
                generator.Init(new KeyGenerationParameters(new SecureRandom(), 2048));
                keyPair = generator.GenerateKeyPair();
                Debug.WriteLine("Generated, saving...");

                SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public);
                byte[] bytePub = publicKeyInfo.ToAsn1Object().GetDerEncoded();

                Directory.CreateDirectory(Path.GetDirectoryName(path));
                File.WriteAllBytes(path + ".pub", bytePub);

                PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private);                        
                byte[] bytePriv = privateKeyInfo.ToAsn1Object().GetDerEncoded();
                File.WriteAllBytes(path + ".priv", bytePriv);

                Debug.WriteLine("Saved session.key");

            }

            //Old method
            /*var generator = new RsaKeyPairGenerator();
            generator.Init(new KeyGenerationParameters(new SecureRandom(), 2048));
            var keyPair = generator.GenerateKeyPair();
            */

            keyParameters = (RsaKeyParameters)keyPair.Private;
            SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public);
            return info.GetEncoded();
        }
开发者ID:mctraveler,项目名称:MineSharp,代码行数:45,代码来源:CryptoMC.cs

示例15: DecodePublicKey

        public static void DecodePublicKey(byte[] data)
        {
            /*TcpClient Client = new TcpClient();
            Client.Connect(IPAddress.Parse("127.0.0.1"), 3128);
            BinaryWriter bwr = new BinaryWriter(Client.GetStream());
            bwr.Write((byte)1);
            bwr.Write(data, 0, 162);*/

            AsymmetricKeyParameter kp = PublicKeyFactory.CreateKey(data);
            Key = (RsaKeyParameters)kp;
            PublicKey = new byte[data.Length];
            data.CopyTo(PublicKey,0);

            //Console.WriteLine("Exponent: " + Key.Exponent + "\nModulus: " + Key.Modulus);

            CipherKeyGenerator keygen = new CipherKeyGenerator();
            keygen.Init(new KeyGenerationParameters(new SecureRandom(), 128));
            SecretKey = keygen.GenerateKey();
        }
开发者ID:ReezeBL,项目名称:MinecraftEmu,代码行数:19,代码来源:CryptManager.cs


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