title: AES encryption on files using PowerShell
body: <p>I was able to AES encrypt files successfully using this script <a href="https://gallery.technet.microsoft.com/EncryptDecrypt-files-use-65e7ae5d/file/165403/14/" rel="nofollow noreferrer">here</a>, using Windows&nbsp;10, PowerShell version&nbsp;5.1. </p>
  
  <p>When I tried running it on Windows&nbsp;7, PowerShell v2.0, I get an error:</p>
  
  <pre>
  New-CryptographyKey : You cannot call a method on a null-valued expression.
  At C:\Users\IEUser\Desktop\enc.ps1:399 char:27
  + $key = New-CryptographyKey &lt;&lt;&lt;&lt;  -AsPlainText
      + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-CryptographyKey
  
  Protect-File : Cannot bind argument to parameter 'KeyAsPlainText' because
  it is an empty string.
  At C:\Users\IEUser\Desktop\enc.ps1:401 char:77
  + Protect-File -FileName "$env:userprofile/Desktop/secret.txt" -KeyAsPlainText &lt;&lt;&lt;&lt;  $key
      + CategoryInfo          : InvalidData: (:) [Protect-File], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Protect-File
  </pre>
  
  <p>How do I make it work? Or is there another cross-compatible solution for AES file encryption using Powershell?</p>
  
  <p>EDIT:</p>
  
  <p>I might've found a solution with openSSL, but I still tried @Mike Twc's solution, got this output:</p>
  
  <pre><code>PS C:\Users\IEUser\Desktop&gt; .\bouncy.ps1
  
  TEST:
  
  message: Some secret message
  key: 9JODwRWWHp6+uACUiydFXNXPmWDHbcObhgqR/cvZ9zg=
  IV (base64): U29tZV9QYXNzd29yZA==
  IV (utf8): Some_Password
  message bytes: 83 111 109 101 32 115 101 99 114 101 116 32 109 101 115 115 97 10
  3 101
  encrypted message bytes: 178 172 14 98 228 38 129 136 217 25 129 96 46 177 75 62
   50 5 190 46 51 108 81 38 90 74 197 166 44 96 120 252
  encrypted message: sqwOYuQmgYjZGYFgLrFLPjIFvi4zbFEmWkrFpixgePw=
  decrypted bytes: 83 111 109 101 32 115 101 99 114 101 116 32 109 101 115 115 97
  103 101 0 0 0 0 0 0 0 0 0 0 0 0 0
  decrypted message: Some secret message
  </code></pre>