Skip to content

Instantly share code, notes, and snippets.

@NeuronButter
Created December 9, 2025 00:46
Show Gist options
  • Select an option

  • Save NeuronButter/bd95b8e8fa1d9dd92be66dfb258da866 to your computer and use it in GitHub Desktop.

Select an option

Save NeuronButter/bd95b8e8fa1d9dd92be66dfb258da866 to your computer and use it in GitHub Desktop.
PEM to RSAParameters
$pem = Get-Content "path.pem" -Raw
$pem = $pem -replace "-----BEGIN PUBLIC KEY-----", ""
$pem = $pem -replace "-----END PUBLIC KEY-----", ""
$pem = $pem -replace "\s+", ""
$bytes = [System.Convert]::FromBase64String($pem)
$rsa = [System.Security.Cryptography.RSA]::Create()
$rsa.ImportSubjectPublicKeyInfo($bytes, [ref]0)
$n = [Convert]::ToBase64String($rsa.ExportParameters($false).Modulus)
$e = [Convert]::ToBase64String($rsa.ExportParameters($false).Exponent)
Write-Output "`nExponent: $e`n`nModulus: $n`n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment