1
0
mirror of https://github.com/jakeswenson/BitBetter.git synced 2023-10-10 13:36:57 +02:00
BitBetter/generateKeys.ps1

22 lines
999 B
PowerShell
Raw Normal View History

2023-01-03 13:05:03 +01:00
# get the basic openssl binary path
2023-01-02 20:59:14 +01:00
$opensslbinary = "$Env:Programfiles\OpenSSL-Win64\bin\openssl.exe"
2023-01-03 13:05:03 +01:00
# if openssl is not installed attempt to install it
2023-01-02 20:59:14 +01:00
if (!(Get-Command $opensslbinary -errorAction SilentlyContinue))
{
winget install openssl
}
2023-01-03 13:05:03 +01:00
# if previous keys exist, remove them
2023-01-02 20:59:14 +01:00
if (Test-Path "$pwd\.keys")
{
Remove-Item "$pwd\.keys" -Recurse -Force
}
2023-01-03 13:05:03 +01:00
# create new directory
2023-01-02 20:59:14 +01:00
New-item -ItemType Directory -Path "$pwd\.keys"
2023-01-03 13:05:03 +01:00
# generate actual keys
2023-01-02 20:59:14 +01:00
Invoke-Expression "& '$opensslbinary' req -x509 -newkey rsa:4096 -keyout `"$pwd\.keys\key.pem`" -out `"$pwd\.keys\cert.cert`" -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test"
Invoke-Expression "& '$opensslbinary' x509 -inform DER -in `"$pwd\.keys\cert.cert`" -out `"$pwd\.keys\cert.pem`""
Invoke-Expression "& '$opensslbinary' pkcs12 -export -out `"$pwd\.keys\cert.pfx`" -inkey `"$pwd\.keys\key.pem`" -in `"$pwd\.keys\cert.pem`" -passin pass:test -passout pass:test"