EDITED:
After the suggestions that I had from your part, I am trying to adapt the codes. The original code is: (get-credential).Password | ConvertFrom-SecureString -key (get-content E:\Scripting\aes.key) | set-content "E:\Scripting\password.txt"
and I am trying to adapt it with my situation Read-Host "Enter password" | ConvertFrom-SecureString -key (get-content C:\Users\xax.3\Desktop\uipath\TheKey.key) | set-content "C:\Users\xax.3\Desktop\uipath\PW.txt"
but it says:
ConvertFrom-SecureString : The input object cannot be bound to any parameters for the command either because the
command does not take pipeline input or the input and its properties do not match any of the parameters that take
pipeline input.
I am new in PowerShell and I am trying to work on a project. In the project I have a login part that locally works ( I encrypt a password save it in a .txt file and later I Decrypt it in my code and it works) but when I try it remotely ( I take the encrypted file with copy paste and add it in the folder that I will use remotely)looks like it gives errors. I have already read about this issue in your forum but still with the changes my code is not working.
The code I use to encrypt is:
Read-Host "Enter password" -AsSecureString |
ConvertFrom-SecureString |
Out-File "C:\Users\xax.3\Desktop\uipath\Pass.txt"
This code saves my encrypted pass in the file Pass.Txt and than when I go remotely and I do :
$SecurePassword = Get-Content C:\Users\abc.1\Desktop\uipath\Pass.txt |ConvertTo-SecureString
$UnsecurePassword = (New-Object PSCredential "user",$SecurePassword).GetNetworkCredential().Password
THE ERROR
: ConvertTo-SecureString : Key not valid for use in specified state.
At C:\Users\abc.1\Desktop\uipath\Get_machine_Key.ps1:16 char:75
+ ... nt C:\Users\abc.1\Desktop\uipath\Pass.txt | ConvertTo-SecureString
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], CryptographicException
+ FullyQualifiedErrorId : ImportSecureString_InvalidArgument_CryptographicError,Microsoft.PowerShell.Commands.Conv
ertToSecureStringCommand
New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument
"password" is null. Change the value of argument "password" to a non-null value."
At C:\Users\abc.1\Desktop\uipath\Get_machine_Key.ps1:17 char:22
+ ... urePassword = (New-Object PSCredential "user",$SecurePassword).GetNet ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Any Idea what am I doing bad? looks like the password is NUll i think, just to mention I dont have any key, just a simple password like for example abc123