當前位置: 首頁>>代碼示例>>C#>>正文


C# Cryptography.RSAPKCS1SignatureDeformatter類代碼示例

本文整理匯總了C#中System.Security.Cryptography.RSAPKCS1SignatureDeformatter的典型用法代碼示例。如果您正苦於以下問題:C# RSAPKCS1SignatureDeformatter類的具體用法?C# RSAPKCS1SignatureDeformatter怎麽用?C# RSAPKCS1SignatureDeformatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RSAPKCS1SignatureDeformatter類屬於System.Security.Cryptography命名空間,在下文中一共展示了RSAPKCS1SignatureDeformatter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RSAConstructors

		public void RSAConstructors () 
		{
			RSAPKCS1SignatureDeformatter fmt;
			fmt = new RSAPKCS1SignatureDeformatter ();

			fmt = new RSAPKCS1SignatureDeformatter (rsa);
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:7,代碼來源:RSAPKCS1SignatureDeformatterTest.cs

示例2: Validate

        /// <summary>
        /// ��ע����Ϣ���ݲ��÷ǶԳƼ��ܵķ�ʽ����
        /// </summary>
        /// <param name="originalString">δ���ܵ��ı����������</param>
        /// <param name="encrytedString">���ܺ���ı�����ע�����к�</param>
        /// <returns>�����֤�ɹ�����True������ΪFalse</returns>
        public static bool Validate(string originalString, string encrytedString)
        {
            bool bPassed = false;
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
            {
                try
                {
                    rsa.FromXmlString(UIConstants.PublicKey); //��Կ
                    RSAPKCS1SignatureDeformatter formatter = new RSAPKCS1SignatureDeformatter(rsa);
                    formatter.SetHashAlgorithm("SHA1");

                    byte[] key = Convert.FromBase64String(encrytedString); //��֤
                    SHA1Managed sha = new SHA1Managed();
                    byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(originalString));
                    if (formatter.VerifySignature(name, key))
                    {
                        bPassed = true;
                    }
                }
                catch
                {
                }
            }
            return bPassed;
        }
開發者ID:Andy-Yin,項目名稱:MY_OA_RM,代碼行數:31,代碼來源:RSASecurityHelper.cs

示例3: Verify

        public static bool Verify(Stream input, Stream output, string publicKey)
        {
            // ファイルから情報の抽出
            var buffer = new byte[64];
            if (input.Read(buffer, 0, 64) < 64)
                throw new Exception("File is corrupted.(KSIG: Magic Not Found)");
            var magicstr = Encoding.UTF8.GetString(buffer).Split(new[] { ":" }, StringSplitOptions.None);
            if (magicstr.Length < 2)
                throw new Exception("File is corrupted.(KSIG: Invalid Magic Length)");
            if (magicstr[0] != MagicStr)
                throw new Exception("File is corrupted.(KSIG: Invalid Magic String)");
            var siglen = int.Parse(magicstr[1]);
            var sigbuf = new byte[siglen];
            if (input.Read(sigbuf, 0, siglen) < siglen)
                throw new Exception("File is corrupted.(KSIG: Invalid Signature)");
            var data = ReadAllBytes(input);

            using (var sha = new SHA256Managed())
            using (var rsa = new RSACryptoServiceProvider())
            {
                // Compute hash
                var hash = sha.ComputeHash(data);
                // RSA Initialize
                rsa.FromXmlString(publicKey);
                // deformat
                var deformatter = new RSAPKCS1SignatureDeformatter(rsa);
                deformatter.SetHashAlgorithm("SHA256");
                if (!deformatter.VerifySignature(hash, sigbuf))
                    return false;
            }
            output.Write(data, 0, data.Length);
            return true;
        }
開發者ID:Kei-Nanigashi,項目名稱:StarryEyes,代碼行數:33,代碼來源:Cryptography.cs

示例4: CerRSAVerifySignature

 /// <summary>
 /// 引用證書非對稱加/解密RSA-公鑰驗簽【OriginalString:原文;SignatureString:簽名字符;pubkey_path:證書路徑;CertificatePW:證書密碼;SignType:簽名摘要類型(1:MD5,2:SHA1)】
 /// </summary>
 public static bool CerRSAVerifySignature(string OriginalString, string SignatureString, string pubkey_path, string CertificatePW, int SignType)
 {
     byte[] OriginalByte = System.Text.Encoding.UTF8.GetBytes(OriginalString);
     byte[] SignatureByte = Convert.FromBase64String(SignatureString);
     X509Certificate2 x509_Cer1 = new X509Certificate2(pubkey_path, CertificatePW);
     RSACryptoServiceProvider rsapub = (RSACryptoServiceProvider)x509_Cer1.PublicKey.Key;
     rsapub.ImportCspBlob(rsapub.ExportCspBlob(false));
     RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsapub);
     byte[] HashData;
     switch (SignType)
     {
         case 1:
             f.SetHashAlgorithm("MD5");//摘要算法MD5
             MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
             HashData = md5.ComputeHash(OriginalByte);
             break;
         default:
             f.SetHashAlgorithm("SHA1");//摘要算法SHA1
             SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();
             HashData = sha.ComputeHash(OriginalByte);
             break;
     }
     if (f.VerifySignature(HashData, SignatureByte))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
開發者ID:jxzly229190,項目名稱:OnlineStore,代碼行數:34,代碼來源:99BillController.cs

示例5: CompareCode

        public static bool CompareCode(string regcode)
        {
            if (regcode == null || regcode == "")
            {
                return false;
            }
            try
            {
                string toolcode = GetDiskVolumeSerialNumber() + GetCpuSerialNumber();
                string pubkey = "<RSAKeyValue><Modulus>xe3teTUwLgmbiwFJwWEQnshhKxgcasglGsfNVFTk0hdqKc9i7wb+gG7HOdPZLh65QyBcFfzdlrawwVkiPEL5kNTX1q3JW5J49mTVZqWd3w49reaLd8StHRYJdyGAL4ZovBhSTThETi+zYvgQ5SvCGkM6/xXOz+lkMaEgeFcjQQs=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
                string prikey = "<RSAKeyValue><Modulus>xe3teTUwLgmbiwFJwWEQnshhKxgcasglGsfNVFTk0hdqKc9i7wb+gG7HOdPZLh65QyBcFfzdlrawwVkiPEL5kNTX1q3JW5J49mTVZqWd3w49reaLd8StHRYJdyGAL4ZovBhSTThETi+zYvgQ5SvCGkM6/xXOz+lkMaEgeFcjQQs=</Modulus><Exponent>AQAB</Exponent><P>5flMAd7IrUTx92yomBdJBPDzp1Kclpaw4uXB1Ht+YXqwLW/9icI6mcv7d2O0kuVLSWj8DPZJol9V8AtvHkC3oQ==</P><Q>3FRA9UWcFrVPvGR5bewcL7YqkCMZlybV/t6nCH+gyMfbEvgk+p04F+j8WiHDykWj+BahjScjwyF5SGADbrfJKw==</Q><DP>b4WOU1XbERNfF3JM67xW/5ttPNX185zN2Ko8bbMZXWImr1IgrD5RNqXRo1rphVbGRKoxmIOSv7flr8uLrisKIQ==</DP><DQ>otSZlSq2qomgvgg7PaOLSS+F0TQ/i1emO0/tffhkqT4ah7BgE97xP6puJWZivjAteAGxrxHH+kPY0EY1AzRMNQ==</DQ><InverseQ>Sxyz0fEf5m7GrzAngLDRP/i+QDikJFfM6qPyr3Ub6Y5RRsFbeOWY1tX3jmV31zv4cgJ6donH7W2dSBPi67sSsw==</InverseQ><D>nVqofsIgSZltxTcC8fA/DFz1kxMaFHKFvSK3RKIxQC1JQ3ASkUEYN/baAElB0f6u/oTNcNWVPOqE31IDe7ErQelVc4D26RgFd5V7dSsF3nVz00s4mq1qUBnCBLPIrdb0rcQZ8FUQTsd96qW8Foave4tm8vspbM65iVUBBVdSYYE=</D></RSAKeyValue>";

                using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
                {

                    rsa.FromXmlString(pubkey);

                    RSAPKCS1SignatureDeformatter f = new RSAPKCS1SignatureDeformatter(rsa);

                    f.SetHashAlgorithm("SHA1");

                    SHA1Managed sha = new SHA1Managed();

                    byte[] name = sha.ComputeHash(ASCIIEncoding.ASCII.GetBytes(toolcode));
                    byte[] key = Convert.FromBase64String(regcode);

                    return f.VerifySignature(name, key);
                }
            }
            catch
            {
                return false;
            }
        }
開發者ID:shumaojie,項目名稱:Packaging,代碼行數:34,代碼來源:PublicFunc.cs

示例6: VerifySignature

        public DigitalSignatureVerificationResult VerifySignature(DigitalSignatureVerificationArguments arguments)
        {
            var res = new DigitalSignatureVerificationResult();
            try
            {
                var rsaProviderSender = new RSACryptoServiceProvider();
                rsaProviderSender.FromXmlString(arguments.PublicKeyForSignatureVerification.ToString());
                var deformatter = new RSAPKCS1SignatureDeformatter(rsaProviderSender);
                deformatter.SetHashAlgorithm(_hashingService.HashAlgorithmCode());
                var hashResult = _hashingService.Hash(arguments.CipherText);
                res.SignaturesMatch = deformatter.VerifySignature(hashResult.HashedBytes, arguments.Signature);
                if (res.SignaturesMatch)
                {
                    var rsaProviderReceiver = new RSACryptoServiceProvider();
                    rsaProviderReceiver.FromXmlString(arguments.FullKeyForDecryption.ToString());
                    var decryptedBytes = rsaProviderReceiver.Decrypt(Convert.FromBase64String(arguments.CipherText), false);
                    res.DecodedText = Encoding.UTF8.GetString(decryptedBytes);
                }

                res.Success = true;
            }
            catch (Exception ex)
            {
                res.ExceptionMessage = ex.Message;
            }

            return res;
        }
開發者ID:richardkundl,項目名稱:SampleDI-IoC,代碼行數:28,代碼來源:RsaPkcs1DigitalSignatureService.cs

示例7: verify

        public bool verify(byte[] sig)
        {
            m_cs.Close();
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
            RSA.ImportParameters(m_RSAKeyInfo);
            RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(RSA);
            RSADeformatter.SetHashAlgorithm("SHA1");

            long i = 0;
            long j = 0;
            byte[] tmp;

            if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0)
            {
                long i1 = (sig[i++] << 24) & 0xff000000;
                long i2 = (sig[i++] << 16) & 0x00ff0000;
                long i3 = (sig[i++] << 8) & 0x0000ff00;
                long i4 = (sig[i++]) & 0x000000ff;
                j = i1 | i2 | i3 | i4;

                i += j;

                i1 = (sig[i++] << 24) & 0xff000000;
                i2 = (sig[i++] << 16) & 0x00ff0000;
                i3 = (sig[i++] << 8) & 0x0000ff00;
                i4 = (sig[i++]) & 0x000000ff;
                j = i1 | i2 | i3 | i4;

                tmp = new byte[j];
                Array.Copy(sig, i, tmp, 0, j);
                sig = tmp;
            }
            return RSADeformatter.VerifySignature(m_sha1, sig);
        }
開發者ID:x893,項目名稱:SharpSSH,代碼行數:34,代碼來源:SignatureRSA.cs

示例8: ValidatePathWithEncodedRSAPKCS1SignatureAndPublicRSAKey

        public static bool ValidatePathWithEncodedRSAPKCS1SignatureAndPublicRSAKey(string path, string base64Signature, string publicKey) {

            try {

                byte[] signature = Convert.FromBase64String(base64Signature);
                byte[] data = File.ReadAllBytes(path);
                SHA256CryptoServiceProvider cryptoTransformSHA256 = new SHA256CryptoServiceProvider();
                byte[] sha256Hash = cryptoTransformSHA256.ComputeHash(data);
                string cleanKey = "";

                string[] lines = publicKey.Split(new char[] {'\n', '\r'});

                foreach (string line in lines) {
                        cleanKey += line.Trim();
                }

                byte[] publicKeyData = Convert.FromBase64String(cleanKey);

                RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
                provider.ImportCspBlob(publicKeyData);
                RSAPKCS1SignatureDeformatter formatter = new RSAPKCS1SignatureDeformatter(provider);
                formatter.SetHashAlgorithm("SHA256");
                return formatter.VerifySignature(sha256Hash, signature);

            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return false;
            }

        }
開發者ID:bt-browser,項目名稱:SparkleDotNET,代碼行數:30,代碼來源:SURSAPKCS1Verifier.cs

示例9: CreateDeformatter

 public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
 {
     if (key == null)
         throw new ArgumentNullException(nameof(key));
     var d = new RSAPKCS1SignatureDeformatter(key);
     d.SetHashAlgorithm(SHA_512);
     return d;
 }
開發者ID:nofuture-git,項目名稱:31g,代碼行數:8,代碼來源:Misc.cs

示例10: RSAConstructors

		public void RSAConstructors () 
		{
			RSAPKCS1SignatureDeformatter fmt;
			fmt = new RSAPKCS1SignatureDeformatter ();
			AssertNotNull ("RSAPKCS1SignatureDeformatter()", fmt);

			fmt = new RSAPKCS1SignatureDeformatter (rsa);
			AssertNotNull ("RSAPKCS1SignatureDeformatter(rsa)", fmt);
		}
開發者ID:jjenki11,項目名稱:blaze-chem-rendering,代碼行數:9,代碼來源:RSAPKCS1SignatureDeformatterTest.cs

示例11: CreateDeformatter

        public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(key);
            deformatter.SetHashAlgorithm("SHA256");
            return deformatter;
        }
開發者ID:scholtz,項目名稱:FastZep,代碼行數:9,代碼來源:RSAPKCS1SHA256SignatureDescription.cs

示例12: CreateDeformatter

        /// <summary>
        /// Create a deformatter
        /// </summary>
        /// <param name="key">Key</param>
        /// <returns>Deformatter</returns>
        public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var df = new RSAPKCS1SignatureDeformatter(key);
            df.SetHashAlgorithm(typeof(SHA256Managed).FullName);
            return df;
        }
開發者ID:CDHDeveloper,項目名稱:authservices,代碼行數:16,代碼來源:ManagedSha256SignatureDescription.cs

示例13: VerifySignature

 public bool VerifySignature(byte[] hash, byte[] signedhash)
 {
     RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
     RSAParameters RSAKeyInfo = new RSAParameters();
     RSAKeyInfo.Modulus = m_public.Modulus;
     RSAKeyInfo.Exponent = m_public.Exponent;
     RSA.ImportParameters(RSAKeyInfo);
     RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(RSA);
     RSADeformatter.SetHashAlgorithm("MD5");
     return RSADeformatter.VerifySignature(hash, signedhash);
 }
開發者ID:sasha2567,項目名稱:8--,代碼行數:11,代碼來源:DigitalSignatureHelper+.cs

示例14: CreateDeformatter

        public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
        {
            if (key == null)
            {
                throw new Exception("Invalid key specified for RSAPKCS1SHA256SignatureDescription!");
            }

            RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(key);
            deformatter.SetHashAlgorithm("SHA256");

            return deformatter;
        }
開發者ID:MNLGD,項目名稱:IDES-Data-Preparation-Dot-Net,代碼行數:12,代碼來源:RSAPKCS1SHA256SignatureDescription.cs

示例15: VerifySignature

		public bool VerifySignature(byte[] hashOfDataToSign, byte[] signature)
		{
			using (var rsa = new RSACryptoServiceProvider(2048))
			{
				rsa.ImportParameters(_publicKey);

				var rsaDeformatter = new RSAPKCS1SignatureDeformatter(rsa);
				rsaDeformatter.SetHashAlgorithm("SHA256");

				return rsaDeformatter.VerifySignature(hashOfDataToSign, signature);
			}
		}
開發者ID:dance2die,項目名稱:Project.EncryptTwitter,代碼行數:12,代碼來源:DigitalSignature.cs


注:本文中的System.Security.Cryptography.RSAPKCS1SignatureDeformatter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。