Skip to content

Instantly share code, notes, and snippets.

@xabim
Created June 5, 2018 14:48
Show Gist options
  • Save xabim/742ad192c48662afa39f226e7332fc63 to your computer and use it in GitHub Desktop.
Save xabim/742ad192c48662afa39f226e7332fc63 to your computer and use it in GitHub Desktop.
Encrypt a plain text with certificate in powershell
$Cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Subject -like "CN=Script Automa*"}
$Password = 'Password'
$EncodedPwd = [system.text.encoding]::UTF8.GetBytes($Password)
$EncryptedBytes = $Cert.PublicKey.Key.Encrypt($EncodedPwd, $true)
$EncryptedPwd = [System.Convert]::ToBase64String($EncryptedBytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment