Fuego.Auth : SecureStore

The SecureStore component allows you to encrypt/decrypt a set of alias/password pairs. You specify a password to encrypt/decrypt the entire collection of alias/password pairs. You can also encrypt each alias/password pair individually by specifying an additional password for each pair.

The SecureStore component is most often used to securely capture authentication data needed to access external applications. Note that the SecureStore component only encrypts/decrypts authentication data; it is your responsibility to ensure that the data is stored in a repository such as a file system, LDAP directory, database, and so on.

Example 1: Encrypting a Set of Alias/Key Pairs

// Creating a SecureStore using empty constructor
sstore = SecureStore()

// Alternative: Creating a SecureStore instance using static
// constructor method:
sstore = SecureStore.create()

// Adding alias/key pairs to a SecureStore instance:
addKeyTo sstore
    using alias = "aliasExample1", 
          key = "savedKeyExample1"
addKeyTo sstore
    using alias = "aliasExample2", 
          key = "savedKeyExample2"
addKeyTo sstore
    using alias = "aliasExample3", 
          key = "savedKeyExample3"

// Encrypting the collection of alias/key pairs into a binary value
encryptedBinary = store(sstore, storageKey : "exampleEncryptionPassword")

// Saving SecureStore data to a file
binFileLength = BinaryFile.writeFromBinaryTo(data : encryptedBinary,
                         name : "myBinaryFile.bin", append : false)
 

Example 2: Loading a SecureStore Instance from an Encrypted Binary Value

// Obtaining the binary value with the encrypted data from a file system
encryptedBinary = BinaryFile.readToBinaryFrom(name : "myBinaryFile.bin")

// Loading the previously encrypted binary value into a SecureStore object
sstore = SecureStore.load(binary : encryptedBinary, storageKey : "exampleEncryptionPassword")]

// Obtaining the key for the alias "aliasExample1"
savedKey2 = getKeyFrom(sstore, alias : "aliasExample1")

Example 3: Using Additional Per-Alias Passwords

// Adding passwords to a SecureStore instance, with additional encryption key for each pair
addKeyTo sstore
    using alias = "aliasExample1", 
          key = "savedKeyExample1",
          entryKey = "examplePairEncryptionPassword1"

addKeyTo sstore
    using alias = "aliasExample2", 
          key = "savedKeyExample2",
          entryKey = "examplePairEncryptionPassword2"

// Loading SecureStore and obtaining the key for alias "aliasExample1",
// specifying an additional encryption password for this alias
sstore = SecureStore.load(binary : encryptedBinary,
                      storageKey : "exampleEncryptionPassword")
savedKey1 = getKeyFrom(sstore, alias : "aliasExample1",
                        entryKey : "examplePairEncryptionPassword1")
       

Example 4: Employing Other Available Options

// Checking for the existence of an alias/password pair
found = isAliasIn(sstore, alias : "aliasExample1")

// Removing an alias from a SecureStore instance
removeKeyFrom sstore using alias = "aliasExample1"

// Iterating over existing aliases in a SecureStore instance
for each alias in sstore.aliases do
  logMessage "Alias="+ alias +
             " password="+getKeyFrom(sstore, alias : alias)
end
Related reference
Fuego.Auth : SecureStoreException