Пример #1
0
        public static void Main(String[] args)
        {
            RSAPubKeyData orsakey = new RSAPubKeyData();

            if (args.Length < 3)
            {
                Console.WriteLine("\nUsage:    RSAPubKeyData.exe public_key data_fn signature_fn");
                return;
            }

            String publickeyfn = args[0];
            String datafn      = args[1];
            String signaturefn = args[2];

            if (!File.Exists(publickeyfn))
            {
                Console.WriteLine("File '{0}' not found.", publickeyfn);
                return;
            }
            if (!File.Exists(datafn))
            {
                Console.WriteLine("File '{0}' not found.", datafn);
                return;
            }
            if (!File.Exists(signaturefn))
            {
                Console.WriteLine("File '{0}' not found.", signaturefn);
                return;
            }

            Console.WriteLine("\n\n-------- Trying to decode keyfile as  X.509 SubjectPublicKeyInfo format --------");
            if (!orsakey.DecodeSubjectPublicKeyInfo(publickeyfn))
            {
                Console.WriteLine("FAILED to decode as X.509 SubjectPublicKeyInfo");
                return;
            }

            Console.WriteLine("Decoded successfully as X.509 SubjectPublicKeyInfo");

            RSAParameters            RSAKeyInfo = new RSAParameters();
            RSACryptoServiceProvider RSA        = new RSACryptoServiceProvider();

            RSAKeyInfo.Modulus  = orsakey.keymodulus;
            RSAKeyInfo.Exponent = orsakey.keyexponent;
            RSA.ImportParameters(RSAKeyInfo);

            byte[] data      = GetFileBytes(datafn);
            byte[] signature = GetFileBytes(signaturefn);

            if (RSA.VerifyData(data, "SHA1", signature))
            {
                Console.WriteLine("The signature is valid.");
            }
            else
            {
                Console.WriteLine("The signature is not valid.");
            }
        }
Пример #2
0
        public static void Main(String[] args)
        {
            RSAPubKeyData orsakey = new RSAPubKeyData();

            if(args.Length<3)
            {
                Console.WriteLine("\nUsage:    RSAPubKeyData.exe public_key data_fn signature_fn");
                return;
            }

            String publickeyfn = args[0];
            String datafn = args[1];
            String signaturefn = args[2];

            if (!File.Exists(publickeyfn))
            {
                Console.WriteLine("File '{0}' not found.", publickeyfn);
                return;
            }
            if (!File.Exists(datafn))
            {
                Console.WriteLine("File '{0}' not found.", datafn);
                return;
            }
            if (!File.Exists(signaturefn))
            {
                Console.WriteLine("File '{0}' not found.", signaturefn);
                return;
            }

            Console.WriteLine("\n\n-------- Trying to decode keyfile as  X.509 SubjectPublicKeyInfo format --------");
            if(!orsakey.DecodeSubjectPublicKeyInfo(publickeyfn))
            {
                Console.WriteLine("FAILED to decode as X.509 SubjectPublicKeyInfo");
                return;
            }

            Console.WriteLine("Decoded successfully as X.509 SubjectPublicKeyInfo");

            RSAParameters RSAKeyInfo = new RSAParameters();
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

            RSAKeyInfo.Modulus = orsakey.keymodulus;
            RSAKeyInfo.Exponent = orsakey.keyexponent;
            RSA.ImportParameters(RSAKeyInfo);

            byte[] data = GetFileBytes(datafn);
            byte[] signature = GetFileBytes(signaturefn);

            if(RSA.VerifyData(data,"SHA1",signature))
            {
                Console.WriteLine("The signature is valid.");
            }
            else
            {
                Console.WriteLine("The signature is not valid.");
            }
        }