TsgcWSAPIKeyManagerMethods › RotateKey

RotateKey Method

Issues a fresh key for the same owner and scopes and marks the old one kksRotated.

Syntax

function RotateKey(const aOldKey: string; out aNewKey: string): Boolean;

Parameters

NameTypeDescription
aOldKeyconst stringRaw plaintext key to rotate. Must currently resolve to an active (or already-rotated within grace) entry.
aNewKeyout stringReceives the freshly issued plaintext key (same owner, same scopes, same remaining TTL). Returned only here — only its hash is persisted.

Return Value

True when the old key was located and the new one issued. False when the old key is unknown, already revoked, or expired. (Boolean)

Remarks

Issues a fresh key for the owner and scopes of the old one, stamps the old entry with status kksRotated and stores a rotation timestamp so ValidateKey keeps accepting it for Rotation.GracePeriodSec seconds — the customer can deploy the new key without an outage. After the grace window elapses the old key is silently invalidated. Fires OnKeyRotated, appends a kaaRotated audit entry and updates Stats. Enable Rotation.Enabled to get the full grace-period behaviour; when disabled, the old key is invalidated immediately.

Example

// Leaked key — issue replacement but keep old one alive 24h during grace
var
  vNewKey: string;
begin
  if sgcWSAPIKeyManager1.RotateKey(vOldKey, vNewKey) then
    SendMail(vCustomer, 'Your new API key: ' + vNewKey);
end;

Back to Methods