If an encryption key is specified by using the Key or SecureKey parameters, the Advanced Encryption Standard (AES) encryption algorithm is used. The specified key must have a length of 128, 192, or 256 bits because those are the key lengths supported by the AES encryption algorithm. If no key is specified, the Windows Data Protection API (DPAPI) is used to encrypt the standard string representation.
1 2 3 4 5 6 7 8 9 10 |
$cadena='abcdefghijk' $clave='clavesecreta123' #La clave para cifrar tiene que ser correcta en tipo System.Byte #ConvertFrom-SecureString : No se puede enlazar el parámetro 'Key'. No se puede convertir el valor "Some secret key" al tipo "System.Byte". Error: "La cadena de entrada no tiene el formato correcto." $clavebyte=[Byte[]]($clave.PadRight(24).Substring(0,24).ToCharArray()) $cadenacifrada=$cadena | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString -Key $clavebyte $cadenacifrada |