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


C# RSA.DecryptValue方法代码示例

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


在下文中一共展示了RSA.DecryptValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RsaOaepDecrypt

        [System.Security.SecurityCritical]  // auto-generated
        internal static byte[] RsaOaepDecrypt (RSA rsa, HashAlgorithm hash, PKCS1MaskGenerationMethod mgf, byte[] encryptedData) {
            int cb = rsa.KeySize / 8;

            // 1. Decode the input data
            // It is important that the Integer to Octet String conversion errors be indistinguishable from the other decoding
            // errors to protect against chosen cipher text attacks
            // A lecture given by James Manger during Crypto 2001 explains the issue in details
            byte[] data = null;
            try {
                data = rsa.DecryptValue(encryptedData);
            }
            catch (CryptographicException) {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
            }

            // 2. Create the hash object so we can get its size info.
            int cbHash = hash.HashSize / 8;

            //  3.  Let maskedSeed be the first hLen octects and maskedDB
            //      be the remaining bytes.
            int zeros = cb - data.Length;
            if (zeros < 0 || zeros >= cbHash)
                throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));

            byte[] seed = new byte[cbHash];
            Buffer.InternalBlockCopy(data, 0, seed, zeros, seed.Length - zeros);

            byte[] DB = new byte[data.Length - seed.Length + zeros];
            Buffer.InternalBlockCopy(data, seed.Length - zeros, DB, 0, DB.Length);

            //  4.  seedMask = MGF(maskedDB, hLen);
            byte[] mask = mgf.GenerateMask(DB, seed.Length);

            //  5.  seed = seedMask XOR maskedSeed
            int i = 0;
            for (i=0; i < seed.Length; i++) {
                seed[i] ^= mask[i];
            }

            //  6.  dbMask = MGF(seed, |EM| - hLen);
            mask = mgf.GenerateMask(seed, DB.Length);

            //  7.  DB = maskedDB xor dbMask
            for (i=0; i < DB.Length; i++) {
                DB[i] = (byte) (DB[i] ^ mask[i]);
            }

            //  8.  pHash = HASH(P)
            hash.ComputeHash(EmptyArray<Byte>.Value);

            //  9.  DB = pHash' || PS || 01 || M
            //  10.  Check that pHash = pHash'

            byte[] hashValue = hash.Hash;
            for (i=0; i < cbHash; i++) {
                if (DB[i] != hashValue[i])
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
            }

            //  Check that PS is all zeros
            for (; i<DB.Length; i++) {
                if (DB[i] == 1)
                    break;
                else if (DB[i] != 0)
                    throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
            }

            if (i == DB.Length)
                throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));

            i++; // skip over the one

            //  11. Output M.
            byte[] output = new byte[DB.Length - i];
            Buffer.InternalBlockCopy(DB, i, output, 0, output.Length);
            return output;
        }
开发者ID:peterdocter,项目名称:referencesource,代码行数:78,代码来源:utils.cs

示例2: RSADP

		// PKCS #1 v.2.1, Section 5.1.2
		public static byte[] RSADP (RSA rsa, byte[] c) 
		{
			// m = c^d mod n
			// Decrypt value may apply CRT optimizations
			return rsa.DecryptValue (c);
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:7,代码来源:PKCS1.cs

示例3: RSASP1

		// PKCS #1 v.2.1, Section 5.2.1
		public static byte[] RSASP1 (RSA rsa, byte[] m) 
		{
			// first form: s = m^d mod n
			// Decrypt value may apply CRT optimizations
			return rsa.DecryptValue (m);
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:7,代码来源:PKCS1.cs

示例4: RsaOaepDecrypt

 internal static byte[] RsaOaepDecrypt(RSA rsa, HashAlgorithm hash, PKCS1MaskGenerationMethod mgf, byte[] encryptedData)
 {
     int num = rsa.KeySize / 8;
     byte[] src = null;
     try
     {
         src = rsa.DecryptValue(encryptedData);
     }
     catch (CryptographicException)
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
     }
     int num2 = hash.HashSize / 8;
     int dstOffsetBytes = num - src.Length;
     if ((dstOffsetBytes < 0) || (dstOffsetBytes >= num2))
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
     }
     byte[] dst = new byte[num2];
     Buffer.InternalBlockCopy(src, 0, dst, dstOffsetBytes, dst.Length - dstOffsetBytes);
     byte[] buffer3 = new byte[(src.Length - dst.Length) + dstOffsetBytes];
     Buffer.InternalBlockCopy(src, dst.Length - dstOffsetBytes, buffer3, 0, buffer3.Length);
     byte[] buffer4 = mgf.GenerateMask(buffer3, dst.Length);
     int index = 0;
     for (index = 0; index < dst.Length; index++)
     {
         dst[index] = (byte) (dst[index] ^ buffer4[index]);
     }
     buffer4 = mgf.GenerateMask(dst, buffer3.Length);
     for (index = 0; index < buffer3.Length; index++)
     {
         buffer3[index] = (byte) (buffer3[index] ^ buffer4[index]);
     }
     hash.ComputeHash(new byte[0]);
     byte[] buffer5 = hash.Hash;
     index = 0;
     while (index < num2)
     {
         if (buffer3[index] != buffer5[index])
         {
             throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
         }
         index++;
     }
     while (index < buffer3.Length)
     {
         if (buffer3[index] == 1)
         {
             break;
         }
         if (buffer3[index] != 0)
         {
             throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
         }
         index++;
     }
     if (index == buffer3.Length)
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_OAEPDecoding"));
     }
     index++;
     byte[] buffer6 = new byte[buffer3.Length - index];
     Buffer.InternalBlockCopy(buffer3, index, buffer6, 0, buffer6.Length);
     return buffer6;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:65,代码来源:Utils.cs


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