Import data to PowertoysRunTOTP from Aegis Authenticator

This article will introduce how to export plain JSON data from Aegis Authenticator and convert it into the format required by PowertoysRunTOTP, helping you import two-factor authentication (2FA) accounts from Aegis into the PowerToys Run TOTP extension.

Warning: Do not keep plain JSON files on your computer for an extended period. It is recommended to store them in encrypted storage, such as pCloud Crypto, or use 7zip to compress and set a secure password to protect the files.

Step 1: Export Plain JSON from Aegis Authenticator

First, export your 2FA account data from Aegis Authenticator. Ensure the exported file is in plain JSON format and save it to a secure location, such as C:\path\to\aegis_export.json.

Step 2: Write a PowerShell Script

Write a PowerShell script to convert the exported Aegis JSON file into the format required by PowertoysRunTOTP. Below is the complete script, which you can copy and paste into Notepad and save as a .ps1 file, for example, convert_aegis_to_powertoysrun.ps1.

$inputFilePath = "P:\Crypto Folder\aegis.json"
$outputFilePath = "$env:LOCALAPPDATA\Microsoft\PowerToys\PowerToys Run\Settings\Plugins\Community.PowerToys.Run.Plugin.TOTP\OTPList.json_new"
try {
    # Read the Aegis JSON file and ensure it uses UTF-8 encoding
    $jsonContent = Get-Content -Raw -Path $inputFilePath -Encoding UTF8

    # Check if the JSON file is empty
    if ($jsonContent -eq $null -or $jsonContent.Trim() -eq "") {
        throw "The Aegis JSON file is empty or contains no content"
    }

    try {
        # Parse the JSON file
        $aegisData = $jsonContent | ConvertFrom-Json
    } catch {
        throw "JSON parsing error: $_"
    }

    # Prepare the JSON structure for PowerToysRunTOTP
    $powerToysRunTOTP = @{
        Version = 2
        Entries = @()
    }

    # Check the structure of the Aegis JSON file
    if ($aegisData.db.entries -ne $null) {
        # Iterate over Aegis entries and extract necessary data
        foreach ($entry in $aegisData.db.entries) {
            $newEntry = @{
                Name = "$($entry.issuer): $($entry.name)"
                Key = $entry.info.secret
                IsEncrypted = $false
            }
            $powerToysRunTOTP.Entries += $newEntry
        }
    } else {
        throw "Entries in the Aegis JSON file are empty or not found"
    }

    # Write the converted data to the PowerToysRunTOTP JSON file
    $powerToysRunTOTP | ConvertTo-Json -Depth 3 | Set-Content -Path $outputFilePath -Encoding UTF8

    Write-Host "Aegis JSON conversion successful and saved to $outputFilePath"
} catch {
    Write-Host "An error occurred during the conversion process: $_"
}

Step 3: Run the PowerShell Script

Method 1: Run via Right-Click on Windows 10 or Later

  1. Ensure PowerToys is closed. This prevents the PowertoysRun OTP extension from overwriting the user-edited file during the process.
  2. Open File Explorer and locate the PowerShell script file you saved, such as convert_aegis_to_powertoysrun.ps1.
  3. Right-click the file and select "Run with PowerShell."
  4. If you see a Windows security warning, select "More info" and then click "Run anyway."

Method 2: Run Using PowerShell Command

  1. Ensure PowerToys is closed. This prevents the PowertoysRun OTP extension from overwriting the user-edited file during the process.
  2. Press Win + X and select "Windows PowerShell (Admin)" or "Windows Terminal (Admin)."
  3. In the PowerShell window, type the following command, without pressing Enter yet (there is a space after -File):
    %%%
    PowerShell -ExecutionPolicy Bypass -File
    %%%
  4. Open File Explorer and locate the PowerShell script file you saved.
  5. Drag and drop the file into the PowerShell window. This will automatically fill in the complete path of the file.
  6. Ensure the command looks like this and then press Enter to execute:
    %%%
    PowerShell -ExecutionPolicy Bypass -File "C:\path\to\convert_aegis_to_powertoysrun.ps1"
    %%%

Step 4: Verify the Import Results

  1. Open PowerToys, which will automatically start the TOTP extension.
  2. Once the PowertoysRun TOTP extension starts, it will automatically encrypt the data in the OTPList.json file.
  3. Open PowerToys Run and check if your 2FA accounts were successfully imported. If everything is correct, you should see your imported accounts and be able to use them for authentication.

Summary

Through the above steps, we successfully converted the plain JSON file exported from Aegis Authenticator and imported it into PowertoysRunTOTP. This method helps you easily manage your 2FA accounts and migrate them between different devices.
If you found this article helpful, please leave a comment, give a thumbs up, or share it with others.

If you have any suggestions, feel free to leave a comment!

Facebook 留言

Posted in Software Tip, Tips.

Leave a Reply

Your email address will not be published. Required fields are marked *