示例#1
0
        }//-----------------fine ramo andata-----------------------------------

        /// <summary>
        /// Decrypt a Config entry, i.e. from Base64 to binary string and then to clear string by
        /// means of simple xor.
        /// --- in: string suitableForXml, singleKey
        /// --- out: string clearSequence
        /// </summary>
        /// <param name="sequence"></param>
        /// <param name="kkey"></param>
        /// <returns></returns>
        public static string DecryptForConfiguration(
            string suitableForXml, // a string in Base64, coming directly from a crypted configuration.
            int kkey               // only simple xor, i.e. one integer kkey.
            )
        {                          //---start ritorno-------------------------------
            if (
                0 > kkey ||
                255 < kkey
                )
            {
                throw new System.Exception("the key must be an integer in [0..255].");
            }// else can continue.
            string backInBinary = null;

            if (0 != kkey)
            {
                backInBinary = ConfigurationLayer2008.CryptoWithinText.fromBase64ToBinary(
                    suitableForXml
                    );
            }
            else// clear
            {
                backInBinary = suitableForXml;
            }
            //
            Common.CryptoStore.Macro.CryptoEngine.theReturnType toBeDecrypted;
            toBeDecrypted.kkey            = kkey.ToString();// it's an object and the library casts it to string.
            toBeDecrypted.cryptedSequence = backInBinary;
            Common.CryptoStore.Macro.CryptoEngine.theReturnType decryptoResult =
                Common.CryptoStore.Micro.SimpleXor.commonCore(
                    toBeDecrypted
                    );
            // ready
            return(decryptoResult.cryptedSequence);
        }//-------------end ritorno------
示例#2
0
        /// <summary>
        /// Encrypt a Config entry with simple xor and then let it available in text format, i.e. in base64
        /// suitable for xml and html.
        /// --- in: string clearSequence, singleKey
        /// --- out: string suitableForXml
        /// </summary>
        /// <param name="sequence"></param>
        /// <param name="kkey"></param>
        /// <returns></returns>
        public static string EncryptForConfiguration(
            string sequence,
            int kkey // only simple xor, i.e. one integer kkey.
            )
        {            //-----------------start ramo andata-----------------------------------
            if (
                0 > kkey ||
                255 < kkey
                )
            {
                throw new System.Exception("the key must be an integer in [0..255].");
            }// else can continue.
            Common.CryptoStore.Macro.CryptoEngine.theReturnType input;// it's a value type. It's enough to declare it to have i t on the stack.
            input.cryptedSequence = sequence;
            input.kkey            = kkey.ToString();// it's an object and the library casts it to string.
            Common.CryptoStore.Macro.CryptoEngine.theReturnType cryptoResult =
                Common.CryptoStore.Micro.SimpleXor.commonCore(
                    input
                    );
            //
            string suitableForXml = null;

            if (0 != kkey)
            {
                suitableForXml = ConfigurationLayer2008.CryptoWithinText.fromBinaryToBase64(
                    cryptoResult.cryptedSequence
                    );
            }
            else// clear
            {
                suitableForXml = cryptoResult.cryptedSequence;
            }
            // ready
            return(suitableForXml);
        }//-----------------fine ramo andata-----------------------------------
示例#3
0
        }//

        /// <summary>
        /// the Entity instance requires this.username and this.password to be initialized, in order for this method to work.
        /// the correctness of (usr, pwd) is checked before the substitution, even if the caller page is in zonaRiservata. So this Entity
        ///     is suitable even to be called from pages in free-zone.
        /// coherence between new_pwd and confirm_new_pwd is in BPL.
        /// web_new_pwd will overwrite the existing one, providing a new couple (kkey, mode).
        /// </summary>
        /// <param name="web_new_pwd"></param>
        /// <returns></returns>
        public bool ChangePwd(
            // web_usr was set in the Entity-member and used by LoadSingleRow.
            string old_password,
            string web_new_pwd          // new password filled on the web-form. Verified in BPL that it's well confirmed.
            // System.Data.SqlClient.SqlTransaction trx COMPULSORY
            )
        {
            bool result = false;

            //
            //-------START---------------- blocchi open-close transazione -------------
            //---transazione-----
            System.Data.SqlClient.SqlTransaction trx  = null;
            System.Data.SqlClient.SqlConnection  conn =
                DbLayer.ConnectionManager.connectWithCustomSingleXpath(
                    "ProxyGeneratorConnections/strings",// compulsory xpath
                    "cv_db_app"
                    );
            if (null != conn)
            {
                trx = conn.BeginTransaction();
            }
            else
            {
                return(false);// no db connection.
            }
            //--END--open transazione-----
            //
            int usrQueryResult =
                this.LoadSingleRow(trx);// get user row: usr,pwd,kky,mode.
            string old_pwd_chiaro =
                Common.CryptoStore.Callers.Decriptazione.DecriptazioneSequenza(
                    this.password,
                    this.kkey,
                    this.mode
                    );

            if (old_password != old_pwd_chiaro)
            {
                usrQueryResult = -1;// set error
            }// else continue
            if (0 == usrQueryResult)
            {
                char mode;
                Common.CryptoStore.Macro.CryptoEngine.theReturnType newPwdCrypted =
                    Common.CryptoStore.Callers.Criptazione.CriptazioneSequenza(
                        web_new_pwd,
                        out mode
                        );
                int updatePwdResult =
                    Proxies.usp_utente_ChangePwd_SERVICE.usp_utente_ChangePwd(
                        this.username,
                        newPwdCrypted.cryptedSequence,
                        (string)(newPwdCrypted.kkey),
                        new string(mode, 1),
                        trx
                        );
                if (0 == updatePwdResult)// success
                {
                    trx.Commit();
                    result = true;
                }
                else// failure
                {
                    trx.Rollback();
                    result = false;
                }
            }// else
            else
            {
                trx.Rollback();
                result = false;
            }
            if (null != trx.Connection)
            {
                if (System.Data.ConnectionState.Open == trx.Connection.State)
                {
                    trx.Connection.Close();
                }
            }
            //--END--close transazione------
            // ready
            return(result);
        }// ChangePwd
示例#4
0
        /// <summary>
        /// gets a NameValueCollection containing an entire config section, in clear mode, which may be crypted in the config file.
        /// sono richieste le chiavi kkkey_key e vkkey_key, oltre a quelle applicative.
        /// </summary>
        /// <param name="configurationSectionXpath"></param>
        /// <returns></returns>
        public static System.Collections.Specialized.NameValueCollection GetCustomSectionInOneShot(
            string configurationSectionXpath // xml path of the section
            )
        {
            System.Collections.Specialized.NameValueCollection result = null;
            System.Collections.Specialized.NameValueCollection theRetrievedSection = null;
            //
            //
            object o =
                System.Configuration.ConfigurationManager.GetSection(
                    configurationSectionXpath);

            if (null == o)
            {
                // la sezione richiesta non e' presente in configurazione.
                return(result);// which, by now, is null.
            }// else continue
            //
            theRetrievedSection =
                (System.Collections.Specialized.NameValueCollection)o;
            //
            //---for the keys---
            string kkkey_value = null;

            kkkey_value = theRetrievedSection.Get("kkkey_key");
            if (null == kkkey_value)
            {
                throw (new System.Exception("la chiave richiesta non è presente nella sezione"));
            }// else continue
            //
            //---for the values---
            string vkkey_value = null;

            vkkey_value = theRetrievedSection.Get("vkkey_key");
            if (null == vkkey_value)
            {
                throw (new System.Exception("la chiave richiesta non è presente nella sezione"));
            }// else continue
            //
            //--start retrieving keys---
            int       cardKeys = theRetrievedSection.Count;
            const int cardPreDefinedKeyValCouples = 2;// sono richieste le due chiavi kkkey_key e vkkey_key, oltre a quelle applicative.

            if (cardKeys <= cardPreDefinedKeyValCouples)
            {
                throw (new System.Exception("la sezione non e' stata configurata nel modo appropriato: sono richieste le chiavi kkkey_key e vkkey_key, oltre a quelle applicative."));
            }// else continue
            result = new System.Collections.Specialized.NameValueCollection(cardKeys - cardPreDefinedKeyValCouples); // the remaining entries of the section, excluded the kkkkkkeys.
            for (int c = cardPreDefinedKeyValCouples; c < cardKeys; c++)//[0..2] busy for kkkkeysss etc..  :-)
            {
                //  get binary string from base64 for key:
                string inBinary = null;
                if ("0" != kkkey_value.Trim())
                {
                    inBinary = ConfigurationLayer2008.CryptoWithinText.fromBase64ToBinary(theRetrievedSection.Keys[c]);
                }
                else
                {
                    inBinary = theRetrievedSection.Keys[c];// key is in clear
                }
                Common.CryptoStore.Macro.CryptoEngine.theReturnType configurationElements;
                configurationElements.cryptedSequence = inBinary;
                configurationElements.kkey            = kkkey_value;// NB. in simpleMode the mode depends on the kkey.
                Common.CryptoStore.Macro.CryptoEngine.theReturnType clearElements =
                    Common.CryptoStore.Micro.SimpleXor.commonCore(
                        configurationElements);
                string tmpKey = clearElements.cryptedSequence;
                result[tmpKey] = null;// it's null until its value gets retrieved.
                //
                //  get binary string from base64 for val:
                if ("0" != vkkey_value.Trim())
                {
                    inBinary = ConfigurationLayer2008.CryptoWithinText.fromBase64ToBinary(theRetrievedSection.Get(theRetrievedSection.Keys[c]));
                }
                else
                {
                    inBinary = theRetrievedSection.Get(theRetrievedSection.Keys[c]);// val is in clear
                }
                configurationElements.cryptedSequence = inBinary;
                configurationElements.kkey            = vkkey_value;// NB. in simpleMode the mode depends on the kkey.
                clearElements =
                    Common.CryptoStore.Micro.SimpleXor.commonCore(
                        configurationElements);
                string tmpVal = clearElements.cryptedSequence;
                result[tmpKey] = tmpVal;// value retrieved and assigned to its key.
            }
            // ready
            return(result);
        } // end GetCustomSectionInOneShot