• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Cryptography.RSAParameters类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: DecryptFromBase64

 /// <summary>
 /// 从base64字符串解密
 /// </summary>
 /// <param name="privateKey"></param>
 /// <param name="content"></param>
 /// <param name="size"></param>
 /// <returns></returns>
 public static string DecryptFromBase64(RSAParameters privateKey, string content, int size = 1024)
 {
     var rsa = new RSACryptoServiceProvider(size);
     rsa.ImportParameters(privateKey);
     var cipherbytes = rsa.Decrypt(content.Base64ToBytes(), false);
     return cipherbytes.FromUtf8Bytes();
 }
开发者ID:DesmondNgW,项目名称:Web,代码行数:14,代码来源:RSACryption.cs


示例2: Init

        private void Init()
        {
            string KeyFile = TAppSettingsManager.GetValue("Server.ChannelEncryption.PrivateKeyfile");

            // read the encryption key from the specified file
            FileInfo fi = new FileInfo(KeyFile);

            if (!fi.Exists)
            {
                throw new RemotingException(
                    String.Format("Specified keyfile {0} does not exist", KeyFile));
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(KeyFile);

            FPrivateKey = new RSAParameters();

            try
            {
                FPrivateKey.D = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "D").InnerText);
                FPrivateKey.P = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "P").InnerText);
                FPrivateKey.Q = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Q").InnerText);
                FPrivateKey.DP = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "DP").InnerText);
                FPrivateKey.DQ = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "DQ").InnerText);
                FPrivateKey.InverseQ = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "InverseQ").InnerText);
                FPrivateKey.Modulus = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Modulus").InnerText);
                FPrivateKey.Exponent = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Exponent").InnerText);
            }
            catch (Exception)
            {
                throw new RemotingException(
                    String.Format("Problems reading the keyfile {0}. Cannot find all attributes of the key.", KeyFile));
            }
        }
开发者ID:js1987,项目名称:openpetragit,代码行数:35,代码来源:ServerSinkProvider.cs


示例3: EnrollCandidate

        /// <summary>
        ///     Enroll a candidate a to Factom. A new chain is created and the candidate data is packed and split into entries for
        ///     that chain.
        ///     This operation is irreversable.
        /// </summary>
        /// <param name="c">The candidate to enroll</param>
        /// <param name="password">The password provided by the candidate</param>
        /// <param name="privKey">The private key to pack the data with</param>
        /// <returns>The chain ID of the enrolled candidate</returns>
        public static byte[] EnrollCandidate(Candidate c, string password, RSAParameters privKey)
        {
            var packed = Pack(c, password, privKey);

            Chain.ChainType factomChain = null;

            foreach (
                var segment in
                    DataSegment.Segmentize(packed,
                        firstSegmentLength: DataSegment.DefaultMaxSegmentLength - ExtIDsLength)) {
                var dataToUpload = segment.Pack();
                var factomEntry = Entry.NewEntry(dataToUpload, null, null);
                if (segment.CurrentSegment == 0) {
                    //New chain
                    factomEntry.ExtIDs = GenerateExtIDs(packed);
                    factomChain = Chain.NewChain(factomEntry);
                    Chain.CommitChain(factomChain, FactomWallet); // Wallet Name
                    Thread.Sleep(10100);
                    Chain.RevealChain(factomChain);
                }
                else {
                    //new entry
                    Debug.Assert(factomChain != null, "factomChain != null");
                    factomEntry.ChainId = factomChain.ChainId;
                    Entry.CommitEntry(factomEntry, FactomWallet);
                    Thread.Sleep(10100);
                    Entry.RevealEntry(factomEntry);
                }
            }

            return factomChain.ChainId;
        }
开发者ID:CryptidID,项目名称:Cryptid,代码行数:41,代码来源:CandidateDelegate.cs


示例4: WriteRSAParamsToFile

        public void WriteRSAParamsToFile(string file)
        {
            using (var sw = new StreamWriter(new FileStream(file, FileMode.Append, FileAccess.Write)))
            {
                var sb = new StringBuilder();

                sb.AppendLine("class RsaStore");
                sb.AppendLine("{");

                // Write all private & public rsa parameters.
                WritePublicByteArray(ref sb, "D", RsaParams.D);
                WritePublicByteArray(ref sb, "DP", RsaParams.DP);
                WritePublicByteArray(ref sb, "DQ", RsaParams.DQ);
                WritePublicByteArray(ref sb, "Exponent", RsaParams.Exponent);
                WritePublicByteArray(ref sb, "InverseQ", RsaParams.InverseQ);
                WritePublicByteArray(ref sb, "Modulus", RsaParams.Modulus);
                WritePublicByteArray(ref sb, "P", RsaParams.P);
                WritePublicByteArray(ref sb, "Q", RsaParams.Q);

                sb.AppendLine("}");

                sw.WriteLine(sb.ToString());
            }

            // Reset all values
            RsaParams = new RSAParameters();
        }
开发者ID:australopitheque,项目名称:Project-WoW,代码行数:27,代码来源:RsaData.cs


示例5: ToPEM

        public static string ToPEM(RSAParameters Parameters)
        {
            StringBuilder sb = new StringBuilder();
            MemoryStream ms = new MemoryStream(),
                         all = new MemoryStream();
            bool hasPrivate = Parameters.D != null;
            string type = hasPrivate ? "PRIVATE" : "PUBLIC";
            byte[] noise = new byte[] { 0x00 };

            sb.AppendFormat("-----BEGIN RSA {0} KEY-----\r\n", type);
            writeBytes(ms, 0x02, noise);
            writeBytes(ms, 0x02, Parameters.Modulus);
            writeBytes(ms, 0x02, Parameters.Exponent);
            if(hasPrivate) {
                writeBytes(ms, 0x02, Parameters.D);
                writeBytes(ms, 0x02, Parameters.P);
                writeBytes(ms, 0x02, Parameters.Q);
                writeBytes(ms, 0x02, Parameters.DP);
                writeBytes(ms, 0x02, Parameters.DQ);
                writeBytes(ms, 0x02, Parameters.InverseQ);
            }

            writeBytes(all, 0x30, ms.ToArray());

            sb.AppendLine(Convert.ToBase64String(all.ToArray(), Base64FormattingOptions.InsertLineBreaks));
            sb.AppendFormat("-----END RSA {0} KEY-----", type);

            return sb.ToString();
        }
开发者ID:strider-,项目名称:Test-Project,代码行数:29,代码来源:RSAKeyReader.cs


示例6: RSAEncrypt

        static public byte[] RSAEncrypt(int bits, byte[] dataToEncrypt, RSAParameters rsaKeyInfo, bool doOAEPPadding)
        {
            try
            {
                byte[] encryptedData;
                //Create a new instance of RSACryptoServiceProvider.
                using (var rsa = new RSACryptoServiceProvider(bits))
                {

                    //Import the RSA Key information. This only needs
                    //toinclude the public key information.
                    rsa.ImportParameters(rsaKeyInfo);

                    var rsaExportParameters = rsa.ExportParameters(true);

                    var rsaFormatter = new RSAPKCS1SignatureFormatter(rsa);
                    rsaFormatter.SetHashAlgorithm("SHA256");

                    //Encrypt the passed byte array and specify OAEP padding.  
                    //OAEP padding is only available on Microsoft Windows XP or
                    //later.  
                    encryptedData = rsa.Encrypt(dataToEncrypt, doOAEPPadding);
                }
                return encryptedData;
            }
            //Catch and display a CryptographicException  
            //to the console.
            catch (CryptographicException e)
            {
                Console.WriteLine(e.Message);

                return null;
            }

        }
开发者ID:dr1s,项目名称:rom_tool,代码行数:35,代码来源:RSA.cs


示例7: ParseAccounts

        private Account[] ParseAccounts(List<ParserHelper.Chunk> chunks, byte[] encryptionKey)
        {
            var accounts = new List<Account>(chunks.Count(i => i.Id == "ACCT"));
            SharedFolder folder = null;
            var rsaKey = new RSAParameters();

            foreach (var i in chunks)
            {
                switch (i.Id)
                {
                    case "ACCT":
                        var account = ParserHelper.Parse_ACCT(i,
                                                              folder == null ? encryptionKey : folder.EncryptionKey,
                                                              folder);
                        if (account != null)
                            accounts.Add(account);
                        break;
                    case "PRIK":
                        rsaKey = ParserHelper.Parse_PRIK(i, encryptionKey);
                        break;
                    case "SHAR":
                        folder = ParserHelper.Parse_SHAR(i, encryptionKey, rsaKey);
                        break;
                }
            }

            return accounts.ToArray();
        }
开发者ID:MartonBoda,项目名称:lastpass-sharp,代码行数:28,代码来源:Vault.cs


示例8: FromXmlString

		public override void FromXmlString (string xmlString) 
		{
			if (xmlString == null)
				throw new ArgumentNullException ("xmlString");

			RSAParameters rsaParams = new RSAParameters ();
			try {
				rsaParams.P = GetNamedParam (xmlString, "P");
				rsaParams.Q = GetNamedParam (xmlString, "Q");
				rsaParams.D = GetNamedParam (xmlString, "D");
				rsaParams.DP = GetNamedParam (xmlString, "DP");
				rsaParams.DQ = GetNamedParam (xmlString, "DQ");
				rsaParams.InverseQ = GetNamedParam (xmlString, "InverseQ");
				rsaParams.Exponent = GetNamedParam (xmlString, "Exponent");
				rsaParams.Modulus = GetNamedParam (xmlString, "Modulus");
				ImportParameters (rsaParams);
			}
			catch (Exception e) {
				ZeroizePrivateKey (rsaParams);
				throw new CryptographicException (
					Locale.GetText ("Couldn't decode XML"), e);
			}
			finally	{
				ZeroizePrivateKey (rsaParams);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:26,代码来源:RSA.cs


示例9: RSAEncrypt

		static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
		{
			try
			{
				byte[] encryptedData;
				// Create a new instance of RSACryptoServiceProvider. 
				using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
				{
					// Import the RSA Key information. This only needs 
					// toinclude the public key information.
					RSA.ImportParameters(RSAKeyInfo);

					// Encrypt the passed byte array and specify OAEP padding.   
					// OAEP padding is only available on Microsoft Windows XP or 
					// later.
					encryptedData = RSA.SignHash(DataToEncrypt, CryptoConfig.MapNameToOID("SHA256"));
				}

				return encryptedData;
			}
			// Catch and display a CryptographicException   
			// to the console. 
			catch (CryptographicException e)
			{
				Console.WriteLine(e.Message);
				return null;
			}
		}
开发者ID:dakahler,项目名称:licensemanager,代码行数:28,代码来源:LicenseInfo.cs


示例10: GetProviderFromDerEncodedRsaPrivateKey

        public void GetProviderFromDerEncodedRsaPrivateKey()
        {
            string keyValid;
            string keyDER = null;

            RSAParameters parameters = new RSAParameters();
            parameters.D = Convert.FromBase64String(@"pRgiRK2tfvFdYcGbiqyJ+rgi/HTAPEnR/dtr87I5ctDwOzBG0qOaB3oiUW7qEU0G0iy4hNc1zaHsjhSZYgKZEHP+Xgs7RJZYOTPI9sqbymrDJDLur7h2pMvsqLhcJjEn6qz+hnLMT046D9uSMg9Tpr0Z6FUiOoAwnUZcSK50gj0=");
            parameters.DP = Convert.FromBase64String(@"w49jS+lsTPP5l8QLmMWeyKQ1PzWpRWsV0DJPHRZFHdjNtQkW1zMn5yJsGJ0a9yqXROv6n3BY18iuqY0S/c2PYw==");
            parameters.DQ = Convert.FromBase64String(@"tzis4VqnqbIsZ/CkcBE6Nz3/Rk9nnU5Bw6JyZMs2DVY3JJtOVdmqzZmQ4KquonW5IH6ti3W3844ao+sHm3o3xQ==");
            parameters.Exponent = Convert.FromBase64String(@"AQAB");
            parameters.InverseQ = Convert.FromBase64String(@"/ihX2MBotgMyCIhbyR8l/7G877/nF5BFIC8RGUJqh0SFovYRHVEleLTK7Pi7eA7+OokKEwshZlfwPuE7xiIKyw==");
            parameters.Modulus = Convert.FromBase64String(@"9ws/iSH6l00F/3HUhoJQyY2Y1iorw0roP9BcZRxEmtEfRzPmLnWwrQpusWJUfK71LQu/OLPD9qtnfQdVIGBMns7gfFJBGq+Dsef7CVRb0HIZv3kqUAh8AI46KIx3xRKsdVY4mh7QZcSdAyHHUi0839yNVbObhXDUNETgT5CzKFU=");
            parameters.P = Convert.FromBase64String(@"/u0mEbvml8X8DrbKBiB0QGX9+G2ALRN+SwasDi7jW65SeBf49ENPxH8iC5XXB/yxQpBV2RojferhdE4Nh1+btw==");
            parameters.Q = Convert.FromBase64String(@"+BWZ2QG6x2gL5qOqfZd6wtP/eQRLVz9OC2IUfw0ZojHuWXt45ybw/F+o+bQmyQcTFYES6hFYTUtWjMgn5IG0Uw==");

            using (RSACryptoServiceProvider providerValid = new RSACryptoServiceProvider())
            {
                providerValid.ImportParameters(parameters);
                keyValid = providerValid.ToXmlString(true);
            }

            byte[] fileBytes = File.ReadAllBytes(@"..\..\..\..\Resources\Tests\private.der");
            using (RSACryptoServiceProvider providerDER = RSACryptoHelper.GetProviderFromDerEncodedRsaPrivateKey(fileBytes))
            {
                if (providerDER != null)
                    keyDER = providerDER.ToXmlString(true);
            }

            Assert.AreEqual(keyValid, keyDER);
        }
开发者ID:ValiMail,项目名称:dkim-exchange,代码行数:30,代码来源:TestRSACryptoHelper.cs


示例11: RegisterMessage

 /// <summary>
 /// konstruktor obiektu RegisterMessage
 /// </summary>
 /// <param name="name">nazwa uzytkownika</param>
 /// <param name="password">haslo</param>
 /// <param name="publicKey">klucz publiczny RSA</param>
 /// <param name="registered">czy zarejestrowany</param>
 public RegisterMessage(string name, string password, RSAParameters publicKey, bool registered)
 {
     username = name;
     this.password = password;
     this.publicKey = publicKey;
     this.isRegistered = registered;
 }
开发者ID:Kubabanka,项目名称:PKRY_15Z_Komunikator,代码行数:14,代码来源:RegisterMessage.cs


示例12: Encrypt2Base64

 /// <summary>
 /// 加密成base64字符串
 /// </summary>
 /// <param name="publicKey"></param>
 /// <param name="content"></param>
 /// <param name="size"></param>
 /// <returns></returns>
 public static string Encrypt2Base64(RSAParameters publicKey, string content, int size = 1024)
 {
     var rsa = new RSACryptoServiceProvider(size);
     rsa.ImportParameters(publicKey);
     var cipherbytes = rsa.Encrypt(content.ToUtf8Bytes(), false);
     return cipherbytes.Bytes2Base64();
 }
开发者ID:DesmondNgW,项目名称:Web,代码行数:14,代码来源:RSACryption.cs


示例13: EncryptData

        public string EncryptData(string data)
        {
            try
            {
                //initialze the byte arrays to the public key information.
                byte[] PublicKey = _publicKey.ToArray();
                byte[] Exponent = _exponent.ToArray();

                //Create a new instance of RSACryptoServiceProvider.
                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

                //Create a new instance of RSAParameters.
                RSAParameters RSAKeyInfo = new RSAParameters();

                //Set RSAKeyInfo to the public key values.
                RSAKeyInfo.Modulus = PublicKey;
                RSAKeyInfo.Exponent = Exponent;

                //Import key parameters into RSA.
                RSA.ImportParameters(RSAKeyInfo);

                var dataBytes = ASCIIEncoding.ASCII.GetBytes(data);
                var encryptedBytes = RSA.Encrypt(dataBytes, false);
                var encryptedValue = BitConverter.ToString(encryptedBytes).Replace("-", "").ToLower();
                return encryptedValue;
            }
            catch (CryptographicException e)
            {
                Console.WriteLine(e.Message);
            }

            return null;
        }
开发者ID:kotylo,项目名称:b315s-change-network,代码行数:33,代码来源:RsaEncryptor.cs


示例14: Decrypt

        /// <summary>
        /// 解密数据
        /// </summary>
        /// <param name="base64code">传入加密数据</param>
        /// <returns>返回解密数据</returns>
        static public string Decrypt(string base64code)
        {

            var a = new FileInfo("E:/100115_SignKey.pub").OpenRead();
            var b = new BufferedStream(a);
            //string c = 
            try
            {
                UnicodeEncoding ByteConverter = new UnicodeEncoding();

                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
                RSA.FromXmlString("");

                RSAParameters rsaParameters = new RSAParameters();

                rsaParameters.Exponent = Convert.FromBase64String("AQAB");
                rsaParameters.Modulus =
                    Convert.FromBase64String(
                        "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyq3xJ3jtuWSWk4nCCgysplqV3DyFGaF7iP7PO2vEUsgEq+vqKr+frlwji2n7A1TbpV7KhEGJIT9LW/9WCdBhlu6gnBdErtAA4Or43ol2K1BnY6VBcLWccloMd3YFHG8gOohCVIDbw863Wg0FNS27SM25U+XQfrNFaqBIa093WgAbwRIK06uzC01sW+soutvk+yAYBtbH7I7/1/dFixHKS2KN/7y3pvmXYBIRuBvn35IqwY3Gk0duEfbEr9F6wm2VKhS1zQG760FrHfhbXR+IN5nSTQBHBkw4QukLLvUqueKYfVdp2/2RCnY/At0bbOcA2tAPohDAfUDRdOZsFiTIMQID");

                byte[] encryptedData;
                byte[] decryptedData;

                encryptedData = Convert.FromBase64String(base64code);

                decryptedData = RSADeCrtypto(encryptedData, rsaParameters, true);
                return ByteConverter.GetString(decryptedData);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return null;
            }
        }
开发者ID:houguohua,项目名称:Scut,代码行数:39,代码来源:LoginFeiliu.cs


示例15: HashAndSignString

        /// <summary>
        /// Hash the data and generate signature
        /// </summary>
        /// <param name="dataToSign"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string HashAndSignString(string dataToSign, RSAParameters key)
        {
            UnicodeEncoding ByteConverter = new UnicodeEncoding();
            byte[] signatureBytes = HashAndSignBytes(ByteConverter.GetBytes(dataToSign), key);

            return ByteConverter.GetString(signatureBytes);
        }
开发者ID:akhleshg,项目名称:datastore-service,代码行数:13,代码来源:CryptographyHelper.cs


示例16: HKeyExchange

        public HKeyExchange(int exponent, string modulus, string privateExponent) :
            this()
        {
            var keys = new RSAParameters();
            Exponent = new BigInteger(exponent);
            keys.Exponent = Exponent.ToByteArray();

            Modulus = BigInteger.Parse("0" + modulus, NumberStyles.HexNumber);
            keys.Modulus = Modulus.ToByteArray();
            Array.Reverse(keys.Modulus);

            if (!string.IsNullOrWhiteSpace(privateExponent))
            {
                PrivateExponent = BigInteger.Parse("0" + privateExponent, NumberStyles.HexNumber);
                keys.D = PrivateExponent.ToByteArray();
                Array.Reverse(keys.D);

                GenerateDHPrimes(256);
                GenerateDHKeys(DHPrime, DHGenerator);
            }

            RSA = new RSACryptoServiceProvider();
            RSA.ImportParameters(keys);

            _blockSize = (RSA.KeySize -
                RSA.LegalKeySizes[0].SkipSize) / 8;
        }
开发者ID:SirJamal,项目名称:Sulakore,代码行数:27,代码来源:HKeyExchange.cs


示例17: MainAsync

        static async Task MainAsync(string[] args)
        {
            var keyClient = new KeyVaultClient((authority, resource, scope) =>
            {
                var adCredential = new ClientCredential(applicationId, applicationSecret);
                var authenticationContext = new AuthenticationContext(authority, null);
                return authenticationContext.AcquireToken(resource, adCredential).AccessToken;
            });

            // Get the key details
            var keyIdentifier = "https://testvaultrahul.vault.azure.net/keys/rahulkey/0f653b06c1d94159bc7090596bbf7784";
            var key = await keyClient.GetKeyAsync(keyIdentifier);
            var publicKey = Convert.ToBase64String(key.Key.N);

            using (var rsa = new RSACryptoServiceProvider())
            {
                var p = new RSAParameters() { Modulus = key.Key.N, Exponent = key.Key.E };
                rsa.ImportParameters(p);
                var byteData = Encoding.Unicode.GetBytes(textToEncrypt);
                
                // Encrypt and Decrypt
                var encryptedText = rsa.Encrypt(byteData, true);
                var decryptedData = await keyClient.DecryptDataAsync(keyIdentifier, "RSA_OAEP", encryptedText);
                var decryptedText = Encoding.Unicode.GetString(decryptedData.Result);

                // Sign and Verify
                var hasher = new SHA256CryptoServiceProvider();
                var digest = hasher.ComputeHash(byteData);
                var signature = await keyClient.SignAsync(keyIdentifier, "RS256", digest);
                var isVerified = rsa.VerifyHash(digest, "Sha256", signature.Result);
            }
        }
开发者ID:nyghtrocker,项目名称:Blog,代码行数:32,代码来源:Program.cs


示例18: GetParams

 public static RSAParameters GetParams()
 {
     RSAParameters parameters = new RSAParameters();
     parameters.Modulus = Convert.FromBase64String(Modulus);
     parameters.Exponent = Convert.FromBase64String(Exponent);
     return parameters;
 }
开发者ID:K0HAX,项目名称:VerificationLibrary,代码行数:7,代码来源:PublicKey.cs


示例19: AsTokenVerificationKey

        public static TokenVerificationKey AsTokenVerificationKey(this JsonWebKey jwk)
        {
            X509Certificate2 cert = null;
            X509CertTokenVerificationKey key = null;

            if (jwk.X5c != null && jwk.X5c.Count > 0)
            {
                cert = new X509Certificate2(Convert.FromBase64String(jwk.X5c.First()));
                key = new X509CertTokenVerificationKey(cert);
                return key;
            }

            if (!String.IsNullOrEmpty(jwk.N) && !String.IsNullOrEmpty(jwk.E))
            {
                RsaTokenVerificationKey rsaToken = new RsaTokenVerificationKey();
                RSAParameters rsaParams = new RSAParameters()
                    {
                        Modulus = EncodeUtilities.Base64UrlDecode(jwk.N),
                        Exponent = EncodeUtilities.Base64UrlDecode(jwk.E)
                    };

                rsaToken.InitFromRsaParameters(rsaParams);
                return rsaToken;
            }
            throw new NotSupportedException(StringTable.NotSupportedJwkToTokenVerificationKeyConversion);
        }
开发者ID:JeromeZhao,项目名称:azure-sdk-for-media-services,代码行数:26,代码来源:JsonWebKeyExtension.cs


示例20: VerifyData

        public static bool VerifyData(string originalMessage, string signedMessage, RSAParameters Parameters)
        {
            bool success = false;
            var encoder = new UTF8Encoding();
            byte[] bytesToVerify = encoder.GetBytes(originalMessage);
            byte[] signedBytes = Convert.FromBase64String(signedMessage);

            RSAParameters parameters = Parameters;

            using (var rsa = new RSACryptoServiceProvider())
            {
                try
                {
                    rsa.ImportParameters(parameters);
                    SHA256Managed Hash = new SHA256Managed();

                    byte[] hashedData = Hash.ComputeHash(bytesToVerify);
                    success = rsa.VerifyData(hashedData, CryptoConfig.MapNameToOID("SHA256"), signedBytes);
                }
                catch (CryptographicException e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
            return success;
        }
开发者ID:K0HAX,项目名称:VerificationLibrary,代码行数:30,代码来源:RSAlib.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cryptography.RandomNumberGenerator类代码示例发布时间:2022-05-26
下一篇:
C# Cryptography.RSAPKCS1SignatureFormatter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap