Listing: TOTP im Detail # Laden der Otp.NET-Bibliothek Add-Type -Path .\lib\Otp.NET.dll # 1. Konvertieren des Base32-kodierten Seed zu einem Byte-Array $base32Seed = "M5K6Z7MDJ6KJ2LHC‘ $bytesSeed = [OtpNet.Base32Encoding]::ToBytes($base32Seed) # 2. Zeitgeber berechnen $unixTime = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() $timeCounter = [Math]::Floor($unixTime / 30) # 3. Counter zu Byte-Array (Big-Endian) $counterBytes = [BitConverter]::GetBytes([int64]$timeCounter) [Array]::Reverse($counterBytes) # 4. HMAC berechnen $hmac = [System.Security.Cryptography.HMACSHA1]::new($bytesSeed) $hash = $hmac.ComputeHash($counterBytes) # 5. Dynamische Trunkierung $offset = $hash[$hash.Length - 1] -band 0x0F $binary = (($hash[$offset] -band 0x7F) -shl 24) -bor (($hash[$offset + 1] -band 0xFF) -shl 16) -bor (($hash[$offset + 2] -band 0xFF) -shl 8) -bor ($hash[$offset + 3] -band 0xFF) # 6. Ausgabe des 6-stelligen OTP-Code ($binary % 1000000).ToString("D6‘)