Created
March 10, 2016 18:04
-
-
Save srvrguy/99e757ec1475c23a2cbf to your computer and use it in GitHub Desktop.
A PowerShell script to make a 2048-bit RSA keypair. Saves the files in XML format in the user's document directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a 2048-bit RSA Keypair in XML format | |
# | |
# @author Michael Johnson <[email protected]> | |
# @copyright 2016 SnapMD, Inc. | |
# @license https://opensource.org/licenses/BSD-2-Clause Simplified BSD License | |
<# | |
Copyright (c) 2016, SnapMD, Inc. | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
1. Redistributions of source code must retain the above copyright notice, this | |
list of conditions and the following disclaimer. | |
2. Redistributions in binary form must reproduce the above copyright notice, | |
this list of conditions and the following disclaimer in the documentation | |
and/or other materials provided with the distribution. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
#> | |
$SavePath = "$env:USERPROFILE\Documents\VC-JWT-Keys" | |
If (Test-Path $SavePath) { | |
Write-Error "It appears this has already been run. If you need to make a new keypair, delete or rename $SavePath" -Category ResourceExists | |
} Else { | |
Write-Host "Creating a 2048-bit RSA Keypair" | |
$rsa = New-Object System.Security.Cryptography.RSACryptoServiceProvider -ArgumentList 2048 | |
# Make a directory for the keys | |
Write-Host "Creating directory $SavePath for storing keys" | |
New-Item $SavePath -ItemType directory | Out-Null | |
Write-Host "Saving private and public keys as private-key.xml and public-key.xml" | |
#Private Key | |
$rsa.toXmlString($true) | Out-File $SavePath\private-key.xml | |
#Public Key | |
$rsa.ToXmlString($false) | Out-File $SavePath\public-key.xml | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment