private string signText(string inputText)
        {
            IPrivKey secretKey = null;

            try
            {
                secretKey = IPriv.openSecretKey(m_Configuration.SecretKeyPath, m_Configuration.SecretKeyPassword);
                return(secretKey.signText(inputText));
            }
            catch (IPrivException err)
            {
                throw new CryptographicException(err + " (код ошибки = " + err.code + ")", err);
            }
            finally
            {
                secretKey?.closeKey();
            }
        }
        private void verifyText(string inputText)
        {
            IPrivKey publicKey = null;

            try
            {
                publicKey = IPriv.openPublicKey(m_Configuration.PublicKeyPath, Convert.ToUInt32(m_Configuration.PublicKeySerial, 10));
                publicKey.verifyText(inputText); // If this step is successfull, then signature is valid
            }
            catch (IPrivException err)
            {
                throw new CryptographicException(err + " (код ошибки = " + err.code + ")", err);
            }
            finally
            {
                publicKey?.closeKey();
            }
        }
        /// <summary>Fail-fast checking of keys opening.</summary>
        private void checkKeys()
        {
            checkKeyPath(m_Configuration.SecretKeyPath);
            checkKeyPath(m_Configuration.PublicKeyPath);

            IPrivKey secretKey = null;
            IPrivKey publicKey = null;

            try
            {
                secretKey = IPriv.openSecretKey(m_Configuration.SecretKeyPath, m_Configuration.SecretKeyPassword);
                publicKey = IPriv.openPublicKey(m_Configuration.PublicKeyPath, Convert.ToUInt32(m_Configuration.PublicKeySerial, 10));
            }
            finally
            {
                secretKey?.closeKey();
                publicKey?.closeKey();
            }
        }
Example #4
0
        private string Sign(string message)
        {
            string   res = null;
            IPrivKey sec = null;

            try
            {
                sec = IPriv.openSecretKey(SecretKey, Password);
                res = sec.signText(message);
            }
            catch (IPrivException ex)
            {
                Functions.AddEvent("Error signing the message!", string.Format("Sign!: [{0}]", ex.Message), EventType.Critical, null, ex);
            }
            if (sec != null)
            {
                sec.closeKey();
            }
            return(res);
        }
Example #5
0
        private bool VerifySign(string message)
        {
            var      res = false;
            IPrivKey pub = null;

            try
            {
                pub = IPriv.openPublicKey(PublicKey, Convert.ToUInt32(SerialNumber, 10));
                pub.verifyText(message);
                Functions.AddEvent("Signature valid!",
                                   string.Format("VerifySign: [{0}]", message), EventType.Info);
                res = true;
            }
            catch (IPrivException ex)
            {
                Functions.AddEvent("Error during signature verification!", string.Format("VerifySign!: [{0}]", ex.Message), EventType.Critical, null, ex);
            }
            if (pub != null)
            {
                pub.closeKey();
            }
            return(res);
        }