Advertisement
Guest User

Untitled

a guest
May 27th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. # @OneLogicalMyth
  2. function New-cPassword($unencryptedString) {
  3. # encrypt string to known AES key used by cPassword
  4. $AesObject = New-Object System.Security.Cryptography.AesCryptoServiceProvider
  5. $AesObject.Mode = [System.Security.Cryptography.CipherMode]::CBC
  6. $AesObject.IV = New-Object Byte[]($AesObject.IV.Length)
  7. $AesObject.KeySize = 256
  8. $AesObject.Key = @(0x4e,0x99,0x06,0xe8,0xfc,0xb6,0x6c,0xc9,0xfa,0xf4,0x93,0x10,0x62,0x0f,0xfe,0xe8,
  9. 0xf4,0x96,0xe8,0x06,0xcc,0x05,0x79,0x90,0x20,0x9b,0x09,0xa4,0x33,0xb6,0x6c,0x1b)
  10. $encryptor = $AesObject.CreateEncryptor()
  11. $bytes = [System.Text.Encoding]::Unicode.GetBytes($unencryptedString)
  12. $encryptedData = $encryptor.TransformFinalBlock($bytes, 0, $bytes.Length);
  13. $cPassword = [System.Convert]::ToBase64String($encryptedData)
  14.  
  15. # remove padding so it matches cPassword and return b64 string
  16. return $cPassword.Replace('=','')
  17. }
  18.  
  19. # Example - New-cPassword -unencryptedString 'Test*P4ssword!'
  20. # Generates an encrypted password for Group Policy Preferences (GPP), ideal for labs.
  21. # You should never use a GPP password on your production systems.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement