Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
jsira2003@yahoo.com wrote: ↑Sat Jan 26, 2019 1:28 pm
I executed my code with your error catching. I will see if I can catch error before packaging as you said in the ps studio. From what I read it seems as if the expected byte counts are off in the Encrypted string.
This is tricky stuff
John
No. The byte array for the key is wrong.
Be sure you can decrypt your strings using your key at a command prompt.
First all let me say I appreciate all your help! I saw the many listing on the web regarding this ugly error. It certainly is ugly. The thing I cannot wrap my head around is the following:
It does not work as a packaged app. Yet is work perfectly in ise. As you can see once the function has the file and the key we are off to the races! I am perplexed why it would work in one area and not the other area. The same function, the same key with the same file and different results! I am also using this is another app with good results as well. In this other packaged app it seems to be working reliably.
I am thinking to try a .net function that will import the file into an array within the package. It must be the handling of the file in the package that is causing there to be a difference in the array containing the data. I tried to use options of get-content like raw and only changed the error message.
I am still stuck with padding is invalid and cannot be removed. I am reading up on the web for clues. There are alot of dead ends.
This fix is extremely important to my application. I have to get this resolved. I still feel like I'm missing something. I think this the kind of error if you don't figure out the correct resolve it will come back and bite you!
Here is a good way to create valid and storable keys. Note that keys require 16,24 0r 32 byte arrays and the array must be filled. This method guarantees that key length and character fill will be correct.
# generate a custom key with correct length
$keyLength = 16 # valid values are 16,24,32
$EncryptKey = [byte[]]::New($keyLength)
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($EncryptKey)
$EncryptKey
# to get the string value
[system.Text.Encoding]::UTF8.GetString($EncryptKey)
# we would normally save this in the registry as a local encrypted (secure) string
# Each account would have to install the key into the registry once.
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.