0

私はRSAアルゴリズムをテストしていますが、間違った秘密鍵(Dパラメーター)で復号化したときに何が起こったのかをテストしようとしています.

RSACryptoServiceProviderデフォルトのコンストラクター(パラメーターなし)で使用しています。バイト配列を暗号化してから、秘密鍵を変更します。このために、RSAParametersオブジェクトにエクスポートして D パラメータを変更し、再度インポートします。次に、情報を復号化すると、元のデータが得られます!!

したがって、これがどのように機能するかについて、私が見逃しているものがあるはずです。これがコードです。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Security.Cryptography;
using Apoyo;

namespace PruebaRSA
{
    class Program
    {
        static void Main(string[] args)
        {
            Ayuda ayuda = new Ayuda();
            byte[] datosOriginales = new byte[10];
            byte[] datosCifrados;
            byte[] datosDescifrados;

            CrearArrayDatos(datosOriginales);

            RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
            datosCifrados = rsaCSP.Encrypt(datosOriginales, false);



            //--------------------------------------------------------------
            //Decrypt with the original Private Key

            datosDescifrados = rsaCSP.Decrypt(datosCifrados, false);

            Console.WriteLine("Texto Cifrado:");
            ayuda.WriteHex(datosCifrados, datosCifrados.Length);
            Console.WriteLine("Texto Descifrado:");
            ayuda.WriteHex(datosDescifrados, datosDescifrados.Length);

            //Change the Private Key
            RSAParameters rsaParameters = rsaCSP.ExportParameters(true);
            byte[] newD = new byte[rsaParameters.D.Length];
            CrearArrayDatos(newD);
            rsaParameters.D = newD;
            rsaCSP.ImportParameters(rsaParameters);

            //Decrypt with the new Private Key
            datosDescifrados = rsaCSP.Decrypt(datosCifrados, false);
            Console.WriteLine("Texto Descifrado:");
            ayuda.WriteHex(datosDescifrados, datosDescifrados.Length);

            rsaParameters = rsaCSP.ExportParameters(true);
            Console.WriteLine("Clave privada utilizada: ");
            ayuda.WriteHex(rsaParameters.D, rsaParameters.D.Length);


            //____________________________________________

            Console.Write("Presionar Tecla");
            Console.Read();

        }

        private static void CrearArrayDatos(byte[] datos)
        {
            for (byte i = 0; i < datos.Length; i++)
            {
                datos[i] = i;
            }
        }
    }
}
4

1 に答える 1

2

RSAParametersには、中国の剰余定理を使用してRSA復号化を高速化するために使用できる追加のパラメーターが含まれています。この方法で復号化するのにDは必要ありません。必要なのはDpとDqだけです。したがって、これら2つのパラメーターのいずれかを変更すると、復号化が失敗することが予想されます。

もちろん、優れたセキュリティのために、.netが整合性チェックも提供し、整合性のないパラメータを持つそのような秘密鍵を検出できるようにすると便利です。(そのような整合性チェックが実装されていないのか、それとも見つからないのかはわかりません)。

于 2012-12-10T12:41:39.883 に答える