Create generate-key.ps1

This commit is contained in:
Timo 2025-04-22 15:22:52 +02:00 committed by GitHub
parent abcb230656
commit 888dab0e06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

25
arduino/generate-key.ps1 Normal file
View file

@ -0,0 +1,25 @@
# AES-128: 16 Byte Key
$keyBytes = New-Object byte[] 16
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($keyBytes)
# ───── Arduino Format ─────
$arduinoFormat = ( $keyBytes | ForEach-Object { "0x{0:X2}" -f $_ } ) -join ", "
$arduinoLine = "byte aes_key[] = { $arduinoFormat };"
# ───── Python Format ─────
$pythonFormat = ( $keyBytes | ForEach-Object { "\x{0:X2}" -f $_ } ) -join ""
$pythonLine = "aes_key = b'" + $pythonFormat + "'"
# ───── Klartext-Hex (ohne 0x oder \x) ─────
$hexPlain = ($keyBytes | ForEach-Object { "{0:X2}" -f $_ }) -join ""
$plainLine = "Plain Hex: " + $hexPlain
# ───── Ausgabe ─────
Write-Host "🔐 AES-128 Schlüssel für Arduino:"
Write-Host $arduinoLine
Write-Host ""
Write-Host "🐍 AES-128 Schlüssel für Python:"
Write-Host $pythonLine
Write-Host ""
Write-Host "🧾 AES-128 Schlüssel im Klartext (Hex):"
Write-Host $plainLine