[Collapse]TestComplete How To
 [Expand]Microsoft Office
 [Collapse]TestComplete Utility Scripts
   Call functions with out-parameters in JScript/viewarticle/42197/
   Check if a function is declared/viewarticle/63954/
   Check if the application has stopped responding/viewarticle/42196/
   Get a Reference to a 64-bit In-Process COM Object/viewarticle/63975/
   Get current Log Items/viewarticle/9047/
   How to hide password from test log/viewarticle/54651/
   Identifying an object by another object located near it/viewarticle/54646/
   Left-Right click an object/viewarticle/26358/
   Log a highlighted window’s image/viewarticle/34812/
   Pass parameters via the command line/viewarticle/9021/
   Run a ClickOnce application/viewarticle/17600/
   Run an individual test item via command line/viewarticle/54655/
   Run the specified group of test items via TestComplete's command line/viewarticle/54654/
   Validate an XML File by its XSD Scheme/viewarticle/42198/
   Work with encrypted data storage/viewarticle/9030/
 [Expand]Third-party Controls
 [Expand]Web Utility Scripts
 [Expand]Windows Utility Scripts
Updated: 7/19/2012 Applies To: TestComplete Rating: GoodGoodGoodGoodGood 3 vote(s) Click to rate: PoorNot badAverageGoodExcellent
Work with encrypted data storage

The script below demonstrates how to work with encrypted data storage. Encrypted information is stored in the SecureStringStorage.dat file that is located in the project suite folder. The algoritm of encoding and decoding is implemented in the SecureStringStorage script extension that you can download below. To know how to install the script extension, read the "Installing and Uninstalling Script Extensions" article.

VBScriptCopy Code

Sub Test
  Dim i, secureStoragePath, password, secureStorage , keys, attemptsCount
  secureStoragePath = Project.Path & "SecureStringStorage.dat"
  password = "TestMessage"
  ' Loads storage data
  Set secureStorage = SecureStringStorage.Load(secureStoragePath, password)
  If Not secureStorage.Item("loaded") Then
    Log.Error("Cannot load secure storage")
    Exit Sub
  End If
  ' Logs storage data
  keys = secureStorage.Item("secureStorageData").Keys() 
  For i = 0 To UBound(keys)
    Log.Message("Item " & keys(i) & ": " &_
  ' Modifies storage data
  attemptsCount = secureStorage.Item("secureStorageData").Item("attemptsCount")
  If Empty = attemptsCount Then
    secureStorage.Item("secureStorageData").Item("attemptsCount") = 1
    secureStorage.Item("secureStorageData").Item("attemptsCount") = CInt(attemptsCount) + 1
  End If
  secureStorage.Item("secureStorageData").Item("A") = "AN_A_ITEM_VALUE"
  secureStorage.Item("secureStorageData").Item("sitePassword") = "MY_SITE_PASSWORD"
  ' Saves storage data
  If Not SecureStringStorage.Save(secureStorage, password) Then
    Log.Error("Cannot save secure storage")
    Exit Sub
  End If
End Sub

JScriptCopy Code

function Test()
  var secureStoragePath = Project.Path + "SecureStringStorage.dat";
  var password = "TestMessage";
  // Loads storage data
  var secureStorage = SecureStringStorage.Load(secureStoragePath, password);
  if (!secureStorage.Item("loaded")) {
    Log.Error("Cannot load secure storage");
  // Logs storage data
  var keys = VBArray(secureStorage.Item("secureStorageData").Keys()).toArray(); 
  for(var i = 0; i < keys.length; i++) {
    Log.Message("Item " + keys[i] + ": " + 
  // Modifies storage data
  var attemptsCount = 
  if (null == attemptsCount) {
    secureStorage.Item("secureStorageData").Item("attemptsCount") = 1;
  else {
    secureStorage.Item("secureStorageData").Item("attemptsCount") = 
                                                  parseInt(attemptsCount) + 1;
  secureStorage.Item("secureStorageData").Item("A") = "AN_A_ITEM_VALUE";
  secureStorage.Item("secureStorageData").Item("sitePassword") = 
  // Saves storage data
  if (!SecureStringStorage.Save(secureStorage, password)) {
    Log.Error("Cannot save secure storage");

© 2018 SmartBear Software. All rights reserved.
Email Send feedback on this document