-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncrypt.ps1
29 lines (24 loc) · 997 Bytes
/
Encrypt.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Param(
[Parameter(
Mandatory=$True,
Position=0,
ValueFromPipeLine=$true
)]
[Alias("String")]
[String]$Phrase,
[Parameter(
Mandatory=$True,
Position=1
)]
[Alias("Key")]
[String]$EncryptionKey
)
Write-Host "Make sure you are passing the Phrase param with the single quote '' so the special chars(like $) will be ignored, and use the decrypt.ps1 to test the result" -ForegroundColor Yellow
#create aes key - keep this secure at all times
$aesKey = $EncryptionKey.Split(",") # example: 20,11,0,4,54,32,144,23,5,3,1,41,36,31,18,175,6,17,1,9,5,1,76,23
# convert to secure string object
$Secure = ConvertTo-SecureString -String $Phrase -AsPlainText -Force
# store secure object - use output in the decryption process. Could be saved to file.
# remember, the aeskey should remain physically secured
$Encrypted = ConvertFrom-SecureString -SecureString $Secure -Key $aesKey
Write-Host "Encrypted:`n$encrypted`n"