-
Notifications
You must be signed in to change notification settings - Fork 2
/
AES-Encrypt.ps1
38 lines (30 loc) · 1.19 KB
/
AES-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
30
31
32
33
34
35
36
37
38
## CODIGO SIN TERMINAR
$dentro= Read-Host "texto"
$contraseña= Read-Host "pass"
$caracteres= $contraseña.Length
if ($caracteres.Trim() -eq "16"){
$unencryptedString = "$dentro"
# Cifrar
$bytes = [System.Text.Encoding]::UTF8.GetBytes($unencryptedString)
$aesManaged = New-Object "System.Security.Cryptography.AesManaged"
$aesManaged.Mode = [System.Security.Cryptography.CipherMode]::ECB
$aesManaged.BlockSize = 128
$aesManaged.Key = [System.Text.Encoding]::UTF8.GetBytes($contraseña)
$encryptor = $aesManaged.CreateEncryptor()
$encryptedData = $encryptor.TransformFinalBlock($bytes, 0, $bytes.Length);
$encrypted = [System.Convert]::ToBase64String($encryptedData)
$encrypted
}
elseif($caracteres -lt "16"){
$contraseñaadd= (16 - $contraseña.Length)
## SE AÑADEN X CARACTERES
}
elseif($caracteres -gt "16"){
$contraseñaadd= ($contraseña.Length - "16")
## BORRAR X CARACTERES
}
# Descifrar
$bytes = [System.Convert]::FromBase64String($encrypted)
$decryptor = $aesManaged.CreateDecryptor();
$unencryptedData = $decryptor.TransformFinalBlock($bytes, 0, $bytes.Length);
[System.Text.Encoding]::UTF8.GetString($unencryptedData).Trim([char]0)