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


C# RSA.EncryptValue方法代码示例

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


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

示例1: RsaOaepEncrypt

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

            //  1. Hash the parameters to get PHash
            int cbHash = hash.HashSize / 8;
            if ((data.Length + 2 + 2*cbHash) > cb)
                throw new CryptographicException(String.Format(null, Environment.GetResourceString("Cryptography_Padding_EncDataTooBig"), cb-2-2*cbHash));
            hash.ComputeHash(EmptyArray<Byte>.Value); // Use an empty octet string

            //  2.  Create DB object
            byte[] DB = new byte[cb - cbHash];

            //  Structure is as follows:
            //      pHash || PS || 01 || M
            //      PS consists of all zeros

            Buffer.InternalBlockCopy(hash.Hash, 0, DB, 0, cbHash);
            DB[DB.Length - data.Length - 1] = 1;
            Buffer.InternalBlockCopy(data, 0, DB, DB.Length-data.Length, data.Length);

            // 3. Create a random value of size hLen
            byte[] seed = new byte[cbHash];
            rng.GetBytes(seed);

            // 4.  Compute the mask value
            byte[] mask = mgf.GenerateMask(seed, DB.Length);

            // 5.  Xor maskDB into DB
            for (int i=0; i < DB.Length; i++) {
                DB[i] = (byte) (DB[i] ^ mask[i]);
            }

            // 6.  Compute seed mask value
            mask = mgf.GenerateMask(DB, cbHash);

            // 7.  Xor mask into seed
            for (int i=0; i < seed.Length; i++) {
                seed[i] ^= mask[i];
            }

            // 8. Concatenate seed and DB to form value to encrypt
            byte[] pad = new byte[cb];
            Buffer.InternalBlockCopy(seed, 0, pad, 0, seed.Length);
            Buffer.InternalBlockCopy(DB, 0, pad, seed.Length, DB.Length);

            return rsa.EncryptValue(pad);
        }
开发者ID:peterdocter,项目名称:referencesource,代码行数:48,代码来源:utils.cs

示例2: RSAEP

		// PKCS #1 v.2.1, Section 5.1.1
		public static byte[] RSAEP (RSA rsa, byte[] m) 
		{
			// c = m^e mod n
			return rsa.EncryptValue (m);
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:6,代码来源:PKCS1.cs

示例3: RSAVP1

		// PKCS #1 v.2.1, Section 5.2.2
		public static byte[] RSAVP1 (RSA rsa, byte[] s) 
		{
			// m = s^e mod n
			return rsa.EncryptValue (s);
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:6,代码来源:PKCS1.cs

示例4: RsaOaepEncrypt

 internal static byte[] RsaOaepEncrypt(RSA rsa, HashAlgorithm hash, PKCS1MaskGenerationMethod mgf, RandomNumberGenerator rng, byte[] data)
 {
     int num = rsa.KeySize / 8;
     int byteCount = hash.HashSize / 8;
     if (((data.Length + 2) + (2 * byteCount)) > num)
     {
         throw new CryptographicException(string.Format(null, Environment.GetResourceString("Cryptography_Padding_EncDataTooBig"), new object[] { (num - 2) - (2 * byteCount) }));
     }
     hash.ComputeHash(new byte[0]);
     byte[] dst = new byte[num - byteCount];
     Buffer.InternalBlockCopy(hash.Hash, 0, dst, 0, byteCount);
     dst[(dst.Length - data.Length) - 1] = 1;
     Buffer.InternalBlockCopy(data, 0, dst, dst.Length - data.Length, data.Length);
     byte[] buffer2 = new byte[byteCount];
     rng.GetBytes(buffer2);
     byte[] buffer3 = mgf.GenerateMask(buffer2, dst.Length);
     for (int i = 0; i < dst.Length; i++)
     {
         dst[i] = (byte) (dst[i] ^ buffer3[i]);
     }
     buffer3 = mgf.GenerateMask(dst, byteCount);
     for (int j = 0; j < buffer2.Length; j++)
     {
         buffer2[j] = (byte) (buffer2[j] ^ buffer3[j]);
     }
     byte[] buffer4 = new byte[num];
     Buffer.InternalBlockCopy(buffer2, 0, buffer4, 0, buffer2.Length);
     Buffer.InternalBlockCopy(dst, 0, buffer4, buffer2.Length, dst.Length);
     return rsa.EncryptValue(buffer4);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:Utils.cs


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