本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}