Powershell加密解密字节

2015-09-22 0 687
Powershell加密解密字节
[Reflection.Assembly]::LoadWithPartialName("System.Security")

 $String=$buff #ARRAY OF BYTES TO ENCODE
 $Passphrase="Pas"
  $salt="My Voice is my P455W0RD!"
  $init="Yet another key"

   $r = new-Object System.Security.Cryptography.AesManaged
   $pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)
   $salt = [Text.Encoding]::UTF8.GetBytes($salt)

   $r.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32) #256/8
   $r.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
   $r.Padding="Zeros"

   $c = $r.CreateEncryptor()
   $ms = new-Object IO.MemoryStream
   $cs = new-Object Security.Cryptography.CryptoStream $ms,$c,"Write"
   $cs.Write($String, 0,$String.Length)
   $cs.Close()
   $ms.Close()
   $r.Clear()
   [byte[]]$Encrypted = $ms.ToArray()

遇见资源网 shell Powershell加密解密字节 http://www.ox520.com/17144.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务