Last active
November 29, 2021 15:46
-
-
Save OneLogicalMyth/16eb16dc5448c131bbdd6137dec7c67e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# @OneLogicalMyth | |
function New-cPassword($unencryptedString) { | |
# encrypt string to known AES key used by cPassword | |
$AesObject = New-Object System.Security.Cryptography.AesCryptoServiceProvider | |
$AesObject.Mode = [System.Security.Cryptography.CipherMode]::CBC | |
$AesObject.IV = New-Object Byte[]($AesObject.IV.Length) | |
$AesObject.KeySize = 256 | |
$AesObject.Key = @(0x4e,0x99,0x06,0xe8,0xfc,0xb6,0x6c,0xc9,0xfa,0xf4,0x93,0x10,0x62,0x0f,0xfe,0xe8, | |
0xf4,0x96,0xe8,0x06,0xcc,0x05,0x79,0x90,0x20,0x9b,0x09,0xa4,0x33,0xb6,0x6c,0x1b) | |
$encryptor = $AesObject.CreateEncryptor() | |
$bytes = [System.Text.Encoding]::Unicode.GetBytes($unencryptedString) | |
$encryptedData = $encryptor.TransformFinalBlock($bytes, 0, $bytes.Length); | |
$cPassword = [System.Convert]::ToBase64String($encryptedData) | |
# remove padding so it matches cPassword and return b64 string | |
return $cPassword.Replace('=','') | |
} | |
# Example - New-cPassword -unencryptedString 'Test*P4ssword!' | |
# Generates an encrypted password for Group Policy Preferences (GPP), ideal for labs. | |
# You should never use a GPP password on your production systems. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment