/// <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); }