Last active
September 19, 2018 00:28
-
-
Save nzbart/a90d3080f595924e649b6d166228cb33 to your computer and use it in GitHub Desktop.
Encryption and decryption using public TLS certificate. This is useful if you want someone to encrypt data to send to you, and you have access to the private key for a public website.
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
$certPassword = Read-Host "Certificate password" | |
$fullCertBytes = <certificate> | |
$fullCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 | |
$fullCert.Import($fullCertBytes, $certPassword, 0) | |
$encrypted = [Convert]::FromBase64String((Read-Host "Encrypted password")) | |
[System.Text.Encoding]::UTF8.GetString(($fullCert.PrivateKey.Decrypt($encrypted, $true))) |
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
$r = [System.Net.HttpWebRequest]::Create(<public website HTTPS url>) | |
$r.GetResponse().Dispose() | |
$cert = $r.ServicePoint.Certificate | |
$password = [System.Text.Encoding]::UTF8.GetBytes((Read-Host "Please enter the text to encrypt")) | |
$out = [Convert]::ToBase64String((New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $cert).PublicKey.Key.Encrypt($password, $true)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment