/// <summary>
        /// Gets the encryption key from AbleCommerce settings
        /// </summary>
        /// <returns>The encryption key</returns>
        public static byte[] GetEncryptionKey()
        {
            //GET THE ABLECOMMERCE SETTINGS
            AbleCommerceEncryptionSection encryptionConfig = AbleCommerceEncryptionSection.GetSection();

            //RETURN THE KEY
            return(encryptionConfig.EncryptionKey.GetKey());
        }
Beispiel #2
0
        /// <summary>
        /// Decrypts all encrypted data in the database, then re-encrypts it using the new encryption key
        /// </summary>
        /// <param name="context">The HttpApplication context to look for the encryption keys</param>
        public static void RecryptDatabase(HttpApplication context)
        {
            // GET OLD AND NEW KEY FROM CONFIG
            AbleCommerceEncryptionSection encryptionConfig = AbleCommerceEncryptionSection.GetSection(context);

            byte[] oldKey = encryptionConfig.OldEncryptionKey.GetKey();
            byte[] newKey = encryptionConfig.EncryptionKey.GetKey();
            RecryptionHelper.RecryptDatabase(oldKey, newKey);
        }
        /// <summary>
        /// Sets the encryption key for the current application
        /// </summary>
        /// <param name="passPhrase">A random string or password that will help form the key.</param>
        /// <returns></returns>
        public static byte[] SetEncryptionKey(string passPhrase)
        {
            //GET THE ABLECOMMERCE SETTINGS
            //IF CONFIG IS NULL, WE DO NOT HAVE AN "UPDATABLE" SECTION
            System.Configuration.Configuration updateableConfig  = null;
            AbleCommerceEncryptionSection      encryptionSection = null;

            try
            {
                encryptionSection = AbleCommerceEncryptionSection.GetUpdatableSection(out updateableConfig);
            }
            catch { }
            if (encryptionSection == null)
            {
                encryptionSection = AbleCommerceEncryptionSection.GetSection();
            }

            //GENERATE THE KEY
            byte[] newKey = GetKeyFromPassPhrase(passPhrase);

            //SAVE THE EXISTING KEY
            byte[] oldKey = encryptionSection.EncryptionKey.GetKey();
            encryptionSection.OldEncryptionKey.SetKey(oldKey);
            //PRESERVE THE OLD CREATE DATE
            encryptionSection.OldEncryptionKey.CreateDate = encryptionSection.EncryptionKey.CreateDate;

            //UPDATE THE KEY
            encryptionSection.EncryptionKey.SetKey(newKey);

            //SET THE RECRYPT FLAG
            RecryptionHelper.SetRecryptionFlag(true);

            //SAVE SETTINGS
            AbleCommerceEncryptionSection.UpdateConfig(updateableConfig, encryptionSection);

            //RECRYPT EXISTING ACCOUNT DATA
            RecryptionHelper.RecryptDatabase(oldKey, newKey);

            //RETURN THE GENERATED KEY
            return(newKey);
        }
        private static void InternalRestoreBackupKey(byte[] keyData)
        {
            //GET THE ABLECOMMERCE SETTINGS
            //IF CONFIG IS NULL, WE DO NOT HAVE AN "UPDATABLE" SECTION
            System.Configuration.Configuration updateableConfig  = null;
            AbleCommerceEncryptionSection      encryptionSection = null;

            try
            {
                encryptionSection = AbleCommerceEncryptionSection.GetUpdatableSection(out updateableConfig);
            }
            catch { }
            if (encryptionSection == null)
            {
                encryptionSection = AbleCommerceEncryptionSection.GetSection();
            }

            //UPDATE THE KEY
            encryptionSection.EncryptionKey.SetKey(keyData);

            //SAVE SETTINGS
            AbleCommerceEncryptionSection.UpdateConfig(updateableConfig, encryptionSection);
        }