SmartBear
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) & ": " &_
secureStorage.Item("secureStorageData").Item(keys(i)))
Next
' Modifies storage data
attemptsCount = secureStorage.Item("secureStorageData").Item("attemptsCount")
If Empty = attemptsCount Then
secureStorage.Item("secureStorageData").Item("attemptsCount") = 1
Else
secureStorage.Item("secureStorageData").Item("attemptsCount") = CInt(attemptsCount) + 1
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")
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");
return;
}
// Logs storage data
var keys = VBArray(secureStorage.Item("secureStorageData").Keys()).toArray();
for(var i = 0; i < keys.length; i++) {
Log.Message("Item " + keys[i] + ": " +
secureStorage.Item("secureStorageData").Item(keys[i]));
// Modifies storage data
var attemptsCount =
secureStorage.Item("secureStorageData").Item("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") =
"MY_SITE_PASSWORD";
// Saves storage data
if (!SecureStringStorage.Save(secureStorage, password)) {
Log.Error("Cannot save secure storage");