GetNetworkCredential difficulties
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: GetNetworkCredential difficulties
I still can't get over works in ise and not packaged. That doesn't make sense. The logic is the same, however the environment is different.
Re: GetNetworkCredential difficulties
How did you create the byte array? It has to be done correctly.
My code works with no issues. Without posting what you have done and just saying it doesn't work is not helpful.
My code works with no issues. Without posting what you have done and just saying it doesn't work is not helpful.
Re: GetNetworkCredential difficulties
You are still not providing sufficient information. We cannot guess at what you are doing.jsira2003@yahoo.com wrote: ↑Sun Jan 27, 2019 6:28 pm I still can't get over works in ise and not packaged. That doesn't make sense. The logic is the same, however the environment is different.
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: GetNetworkCredential difficulties
[byte[]]$global:LilHash1 = (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)
This isn't my actual key but you get the idea.
I used values from 0 - 255. Not the 1-32 as I have shown. I have put 32 values in the parenthesis.
John
This isn't my actual key but you get the idea.
I used values from 0 - 255. Not the 1-32 as I have shown. I have put 32 values in the parenthesis.
John
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: GetNetworkCredential difficulties
I have changed all instances of the key to be the byte array. It appears that the array without the byte cast worked the same as with the byte cast.
John
John
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: GetNetworkCredential difficulties
I tried this:
$Secure2 = $aline | ConvertTo-SecureString -Key ($key) -debug
This is what I got
Exception calling .ctor with 2 argument(s): 'cannot process argument basuse the value of the argument "password" is null. change the value of argument "password" to a non-null value.
John
$Secure2 = $aline | ConvertTo-SecureString -Key ($key) -debug
This is what I got
Exception calling .ctor with 2 argument(s): 'cannot process argument basuse the value of the argument "password" is null. change the value of argument "password" to a non-null value.
John
Re: GetNetworkCredential difficulties
Why do you keep putting parens around $key?jsira2003@yahoo.com wrote: ↑Sun Jan 27, 2019 6:56 pm I tried this:
$Secure2 = $aline | ConvertTo-SecureString -Key ($key) -debug
This is what I got
Exception calling .ctor with 2 argument(s): 'cannot process argument basuse the value of the argument "password" is null. change the value of argument "password" to a non-null value.
John
I ran the code at a prompt and in a packaged EXE and it works with no issues.
- jsira2003@yahoo.com
- Posts: 117
- Last visit: Tue Jul 11, 2023 6:18 am
Re: GetNetworkCredential difficulties
I'll pull the parens out. My code shows that error with the debug.
Crazy stuff!
John
Crazy stuff!
John
Re: GetNetworkCredential difficulties
Here is a complete script that creates a file and decrypts it. It works under all circumstances that I have tried.
Code: Select all
Function DecryptUserKey {
#requires -Version 3
Param (
[string]$File,
[byte[]]$Key
)
$ErrorActionPreference = 'Stop'
Try {
Get-Content $File |
ForEach-Object{
$ss = $_ | ConvertTo-SecureString -Key $Key
([System.Management.Automation.PSCredential]::New('N/A', $ss)).GetNetworkCredential().Password
}
} Catch {
[System.Windows.Forms.MessageBox]::Show($_)
}
}
$Key = [system.Text.Encoding]::UTF8.GetBytes('1234561234567890')
$pwdfile = 'd:\scripts\passwords.txt'
# make encoded file:
$Key = [system.Text.Encoding]::UTF8.GetBytes('1234561234567890')
'password1', 'password2', 'password3' |
ConvertTo-SecureString -AsPlainText -force |
ConvertFrom-SecureString -Key $Key |
Out-File $pwdfile
# decrypt password file
$decrypted = DecryptUserKey -File $pwdfile -Key $key
$decrypted
pause
Re: GetNetworkCredential difficulties
This shows the easiest way to create a key.
Code: Select all
Function DecryptUserKey {
#requires -Version 3
Param (
[string]$File,
[byte[]]$Key
)
$ErrorActionPreference = 'Stop'
Try {
Get-Content $File |
ForEach-Object{
$ss = $_ | ConvertTo-SecureString -Key $Key
([System.Management.Automation.PSCredential]::New('N/A', $ss)).GetNetworkCredential().Password
}
} Catch {
[System.Windows.Forms.MessageBox]::Show($_)
}
}
$keyText = 'aNsdknalkjdspsojdskljlskdjslkjdslkjjls'
# creae 32 character string
$keyString = $keyText.Substring(0,32)
$Key = [system.Text.Encoding]::UTF8.GetBytes($keyString)
$pwdfile = 'd:\scripts\passwords.txt'
# make encoded file:
$Key = [system.Text.Encoding]::UTF8.GetBytes('1234561234567890')
'password1', 'password2', 'password3' |
ConvertTo-SecureString -AsPlainText -force |
ConvertFrom-SecureString -Key $Key |
Out-File $pwdfile
# decrypt password file
$decrypted = DecryptUserKey -File $pwdfile -Key $key
$decrypted
pause