If you are using K2 Five (5.3), you must install Fix Pack 38 or later to follow the steps in this article.
for Fix Pack release notes and download links.
K2 Five (5.1) includes PowerShell commands that allow you decrypt and encrypt database data with your own password. This lets you move data from the K2 database to another SQL instance and use your own encryption password.
On-premises SQL servers use SCSSO key encryption, in which SQL creates a certificate and a master key for that certificate, and then uses it to encrypt the data in the SQL server. SQL Azure does not support this method so you can only use the PowerShell commands in this article with on-premises SQL servers.
Before performing the steps in this article, back up your database.
If you change your encryption password, you take responsibility for your data encryption. If you lose your password, your data cannot be retrieved, even by K2 Support.
List of K2 Database Tables that get Encrypted
Use the following PowerShell command to import the module and make the commands available. Run Windows PowerShell as the Administrator and enter this command in the folder where you extracted the K2 installation package (for example C:\Users\Administrator\Desktop\K2 (5.1004.0000.0)\Installation):
Command Usage Example
In this scenario, you change the default K2 encryption password to something you choose. Then you export and restore the database to another SQL instance and remove the old encryption. Lastly, you add the new encryption with your new password. Enter the following command in Windows PowerShell:
- To keep your data intact you must re-encrypt the database with a password you choose. Make sure you keep this password for later use:
Update-K2Encryption -NewPassword “Your password”
- You can now export the database and restore it to another SQL instance.
- Remove the old K2 Encryption Key from a database you've moved (edit the connection string for your environment):
Remove-K2EncryptionKey -ConnectionString 'Data Source=localhost;Initial Catalog=K2;integrated security=sspi'
- Add the new encryption to the database by adding a master key, certificate and encryption key using the following commands in order (edit the connection string for your environment):
Add-K2MasterKey -ConnectionString 'Data Source=localhost;Initial Catalog=K2;integrated security=sspi'
For the Add-K2EncryptionKey command, use the -p parameter to enter the password you used in step one, and the -Algorithm parameter to set the encryption algorithm. See Microsoft's Data Encryption in SQL Server article for more information on SQL encryption.
Add-K2Certificate -ConnectionString 'Data Source=localhost;Initial Catalog=K2;integrated security=sspi'
Add-K2EncryptionKey -p "Your password" -Algorithm “AES_256” -ConnectionString 'Data Source=localhost;Initial Catalog=K2;integrated security=sspi'
This test scenario shows you how to confirm that you can retrieve data before and after exporting it to a new SQL instance. The first section tests data before a database export and the second section tests data after export and restoration in another SQL instance.
- Open K2 Designer and create a new category called Encryption Test. Open the category and create new SmartObject called EncryptionTest.
- Add the following properties:
- Encrypt each property by selecting a property, clicking Edit, and checking the Encrypt Property option.
- Finish (save) the SmartObject.
- Select Generate a View and generate item and list views.
- Run the item view and insert a few values.
- Run the list view to confirm you have values.
- To check that the values are correctly encrypted in the database, decrypt them in SQL with the following script:
/****** Script for SelectTopNRows command from SSMS ******/
DECLARE @Variab1eName NVARCHAR(Max)
OPEN SYMMETRIC KEY [SCSSOKey] DECRYPTION BY CERTIFICATE [SCHostServerCert];
) AS 'Decrypted',
Encrypted_Text AS 'Encrypted'
) AS 'Decrypted',
Encrypted_number AS 'Encrypted'
CLOSE SYMMETRIC KEY SCSSOKey;
- Import the PowerShell commands as described in the PowerShell Commands section above and update the K2 Encryption with your chosen password as shown in the first step of the Command Usage Example. Then rerun the SQL script from step 8 above and confirm that values are decrypted and match values you entered.
- If the values decrypt and match what you entered, you can now export the database.
Use the following steps to restore the database to another SQL instance, recreate the keys, and confirm the values decrypt correctly by using the following steps.
- Import the PowerShell commands as described in the PowerShell Commands section above and then perform steps three and four of the first Command Usage Example.
- Re-run the SQL script to see if values decrypt successfully.
- If the values return as expected, the database is ready for use.