TsgcWSAPIKeyManagerMethods › ImportKeys

ImportKeys Method

Stream-based import of keys and audit log.

Syntax

procedure ImportKeys(aStream: TStream);

Parameters

NameTypeDescription
aStreamTStreamSource stream positioned at the start of a payload previously produced by ExportKeys or SaveToFile. Read from the current Position to the end.

Remarks

Stream-based counterpart of LoadFromFile. Parses the versioned header, decrypts the payload with Storage.EncryptionKey when needed, then replaces the in-memory key store and audit log with the contents of the stream. Raises on header mismatch, bad decryption or truncated input. Useful for failover (pull state from an HTTP replication endpoint) and for tests (snapshot the store into a TMemoryStream, mutate, then roll back with ImportKeys).

Example

// Pull the key store from a replication endpoint on startup
var
  oStream: TMemoryStream;
begin
  oStream := TMemoryStream.Create;
  try
    oHTTPClient.Get('https://primary/apikeys/replicate', oStream);
    oStream.Position := 0;
    sgcWSAPIKeyManager1.ImportKeys(oStream);
  finally
    sgcFree(oStream);
  end;
end;

Back to Methods