`sfdx force:org:display` fails with `InvalidEncryptedFormatError - The encrypted data is not properly formatted.` for org created with `sf login` command
This was reported to me by an IC2 user and I reproduced it locally using just the two CLIs:
$ sf login org --alias org_alias
Successfully authorized <redacted> with ID <redacted>
$ sfdx force:org:display -u org_alias --json
{
"status": 1,
"name": "InvalidEncryptedFormatError",
"message": "The encrypted data is not properly formatted.",
"exitCode": 1,
"actions": [
"If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org."
],
"commandName": "OrgDisplayCommand",
"stack": "InvalidEncryptedFormatError: The encrypted data is not properly formatted.\n at AuthInfoCrypto.decrypt (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@salesforce\\core\\lib\\crypto.js:112:19)\n at AuthInfoCrypto.crypt (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@salesforce\\core\\lib\\authInfo.js:134:45)\n at AuthInfoCrypto.decryptFields (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@salesforce\\core\\lib\\authInfo.js:123:21)\n at AuthInfo.getFields (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@salesforce\\core\\lib\\authInfo.js:463:46)\n at OrgDisplayCommand.run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@salesforce\\plugin-org\\lib\\commands\\force\\org\\display.js:32:33)\n at async OrgDisplayCommand._run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@salesforce\\command\\lib\\sfdxCommand.js:81:40)\n at async Config.runCommand (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@oclif\\config\\lib\\config.js:173:24)\n at async SfdxMain.run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@oclif\\command\\lib\\main.js:27:9)\n at async SfdxMain._run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\node_modules\\@oclif\\command\\lib\\command.js:43:20)\n at async Object.run (C:\\Users\\Scott\\AppData\\Local\\sfdx\\client\\7.129.0-c662c12\\dist\\cli.js:162:47)",
"warnings": []
}
Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.
@SCWells72 any update you made on this error.
@vikash123accenture no, nothing new to report. Sorry...
@SCWells72 what could be the root cause for this error, i am getting during deployment.
Unfortunately I'm just the reporter of this issue and not really sure what's causing it, but assuming you're seeing the same issue that I reported, the workaround is to authorize the org using sfdx instead of sf.
Hi There,
I got this error while trying to run any sfdx force:source commands against a sandbox.
I re-authorized the sandbox and the errors went away.
Not sure if this will help you, but thought it was worth sharing.
I also encountered this error while running the metadata deployment against scratch org with both sfdx and cci
"commandName": "OrgDisplayCommand",
"stack": "InvalidEncryptedFormatError: The encrypted data is not properly formatted.\n
at AuthInfoCrypto.decrypt
I am encountering this error trying to create a scratch org. I am authorized against a dev hub.
I am also encountering the same issue, detailed log attached, --dev-debug "commandName": "OrgCreateCommand", "stack": "InvalidEncryptedFormatError: The encrypted data is not properly formatted.\n at AuthInfoCrypto.decrypt sfdx-error.pdf
Hey folks 👋🏼
I'm not able to reproduce this on macOS with both CLIs latest-rc, does anyone have a consistent way to repro this?

@arupsarkar-sfdc after you re-auth, are you able to run force:org:display -u <username> successfully? Do you notice this error start happening after a specific command is executed?
I am thinking of deleting [email protected] in .sfdx folder and reauthorize to see if the error is gone.
SUCCESS:
NOTE: You might see many .json files please be careful of which one you are deleting, it should correspond to a particular devhub which is causing the error
- cd ~/.sfdx
- delete the .json file referencing your DevHub in my case for example it is [email protected].
- re auth your DevHub, verify the above json file got created.
- create scratch orgs
👋🏼 just chiming in that I can't reproduce this on Windows either

SUCCESS:
NOTE: You might see many .json files please be careful of which one you are deleting, it should correspond to a particular devhub which is causing the error
- cd ~/.sfdx
- delete the .json file referencing your DevHub in my case for example it is [email protected].
- re auth your DevHub, verify the above json file got created.
- create scratch orgs
This worked for me!
you need log out of alll your orgs with command: sfdx auth:logout --all , after that autorize an org again.
1

2

Regards.
you need log out of alll your orgs with command: sfdx auth:logout --all , after that autorize an org again.
1
2
Regards.
This worked for me. I had the same issue after refreshing sandboxes, but this did the trick.
I am seeing this issue as well. @cristiand391 I can't reliably reproduce this. It also seems to be org specific. It could be that my local project was created too long ago and something is stale. I don't know.
I can temporarily fix this by re-authorizing my org, but it starts failing again after a day or so. VS Code needs to be closed and re-opened to pick-up the re-authorize.
I was just trying to create a simple project for an LWC course using my trailhead account when I ran into this problem. No way am I logging out of ~15 accounts. I ended up changing the password on my trailhead account and re-authorized and it fixed the problem.
Encountered this myself - deleting the username json in ~.sfdx and re-authorising solved it.
The Refresh token was not being encrypted!
We have a fix for this in the works and should be included in the next CLI release candidate.
I am receiving the following error on the latest version of CLI. Is this the same problem or a different one?
sfdx force:package:list -v DH ERROR running force:package:version:list: The encrypted data is not properly formatted.
Try this: If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org.
sfdx force:package:version:list -v DH ERROR running force:package:version:list: The encrypted data is not properly formatted.
Try this: If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org.
I am getting this issue on latest version, my scratch org seems to report fine but the version create always get the below error:
ERROR running force:package:version:create: The encrypted data is not properly formatted.
Try this: If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org.
This was fixed in in sfdx v 7.158.1, see release notes: https://github.com/forcedotcom/cli/tree/main/releasenotes/sfdx#71581-july-7-2022
This issue has not received a response in 7 days. It will auto-close in 7 days unless a response is posted.
still getting an error while executing force:package:version:create command even though I have upgraded the CLI to the latest version. Error: The encrypted data is not properly formatted. If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org. Any workaround for this?
I am getting this issue on latest version, my scratch org seems to report fine but the version create always get the below error:
ERROR running force📦version:create: The encrypted data is not properly formatted.
Try this: If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org.
I am getting this issue on latest version, my scratch org seems to report fine but the version create always get the below error:
ERROR running force📦version:create: The encrypted data is not properly formatted.
Try this: If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org.
@lodossDev Did you get any resolution/workaround for this
@sharique8 - This issue has been fixed. However, if your auth file is not properly encrypted you must re-authorize first as a one-time step. I would first verify that you are on the most recent CLI version including all core plugins. Then I would re-auth to your devhub org. Then run your command. I would also use the force:package:beta:version:create command to ensure that works for you. If you still have a problem, run this command: sfdx doctor --command "force:package:beta:version:create" where the command string contains all the command parameters and values you would use. That will generate a few files including a debug log that you can grep for errors.
@sharique8 - This issue has been fixed. However, if your auth file is not properly encrypted you must re-authorize first as a one-time step. I would first verify that you are on the most recent CLI version including all core plugins. Then I would re-auth to your devhub org. Then run your command. I would also use the
force:package:beta:version:createcommand to ensure that works for you. If you still have a problem, run this command:sfdx doctor --command "force:package:beta:version:create"where the command string contains all the command parameters and values you would use. That will generate a few files including a debug log that you can grep for errors.
@shetzel re-authorizing worked. Thank you for quick response.