Ejemplo n.º 1
0
        /// <summary>
        /// Podpis hasha wiadomości
        /// <param name="message">wiadomość do zahashowania</param>
        /// <returns>podpisany hash</returns>
        /// </summary>
        // prywatne klucze własne
        public byte[] HashSign(byte[] message)
        {
            using (RSA rsa = RSA.Create())
            {
                rsa.ImportParameters(rsaPrivateParams);

                HashProgram hash = new HashProgram();

                return(rsa.SignHash(hash.DoHash(message), HashAlgorithmName.SHA256, spadding));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        public SignProgram()
        {
            SetKeys();
            ToFileRsa(rsaPrivateParams, PublicParameters);
            ReadPublicXml(@"publicKeyPath.xml");
            ReadPrivateXml(@"privateKeyPath.xml");
            timeToSend = DateTime.Now.ToString("MM/dd/yyyy/HH/mm/ss");
            HashProgram hash       = new HashProgram();
            string      hashedTime = Convert.ToBase64String(hash.DoHash(timeToSend));

            AddTimeToBase(hashedTime);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sprawdzenie hasha
        /// </summary>
        /// <param name="rsaParams">parametry RSA (klucz publiczny klienta)</param>
        /// <param name="signedData">wiadomość podpisana</param>
        /// <param name="signature">podpis</param>
        /// <returns>czy hash jest poprawny</returns>
        public bool VerifyHash(RSAParameters rsaParams, byte[] signedData, byte[] signature)
        {
            using (RSA rsa = RSA.Create())
            {
                rsa.ImportParameters(rsaParams);

                bool        dataOK = rsa.VerifyData(signedData, signature, HashAlgorithmName.SHA256, spadding);
                HashProgram hash   = new HashProgram();

                return(rsa.VerifyHash(hash.DoHash(signedData), signature, HashAlgorithmName.SHA256, spadding));
            }
        }
Ejemplo n.º 4
0
        public bool CheckNumbers(string msg, int option)
        {
            bool verifiedAll = false, verifiedTime = false, verifiedKeys = false;

            char[]   charSeparators = new char[] { ' ' };
            string[] result;
            result = msg.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);

            string time = result[0];

            switch (option)
            {
            case 0:
                string modulus = result[1];
                if (clientModulus == modulus)
                {
                    verifiedKeys = true;
                }
                break;

            case 1:
                string exponent = result[1];
                if (clientExponent == exponent)
                {
                    verifiedKeys = true;
                }
                break;

            default:
                break;
            }

            string      fileStream = @"base.txt", line, hashedTime;
            HashProgram hash = new HashProgram();

            hashedTime = Convert.ToBase64String(hash.DoHash(time));

            for (int i = 0; i < File.ReadLines(fileStream).Count(); i++)
            {
                line = File.ReadLines(fileStream).Skip(i).Take(1).First();
                if (line == hashedTime)
                {
                    verifiedTime = true;
                }
            }

            verifiedAll = verifiedKeys && verifiedTime;

            return(verifiedAll);
        }