0

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

Coding M
  • 11
  • 3
  • the idea is I want to encrypt only once the password , for example locally, and the same encrypt use it by adding the file in which I save the encrypted password in the remote folder. – Coding M Jun 29 '22 at 12:37
  • 6
    The encrypted password file is tied _to your account on that system_ - DPAPI derives the key from a combination of your account and the machine's account. This is by design – Mathias R. Jessen Jun 29 '22 at 12:43
  • 3
    You can't eat and keep a cake. If the password needs to be available outside of local DPAPIs care, one needs to [bring the key too](https://stackoverflow.com/q/15580523/503046) - and then it's as good as plaintext. – vonPryz Jun 29 '22 at 12:54
  • thank you for your answers, looks like the issue is really with the key.I am trying to adapt my code with the original code . I will edit my post so u can see the error I get, cuz here in the comment I see its limited and I can not write – Coding M Jun 29 '22 at 14:48

0 Answers0