Error: Failed to create AgentEnvironment

In some cases identity.pem will be modified to identity.pem.encrypted which will make it unreadable

Error: Failed to create AgentEnvironment.
Caused by: Failed to create AgentEnvironment.
  Failed to create AgentEnvironment for network 'ic'.
    Failed to decrypt PEM file: /home/xxx/.config/dfx/identity/nst/identity.pem.encrypted
identity.pem.encrypted

dfx should never encrypt the pem file on its own. Can you tell a bit more about what happened? It prompts you for a password, right?

i used dfx identity new test_1 Created a user and set a password,
started working fine,
But when wsl2 restarts itself due to some problems and then uses this account, although it will remind you to enter the password, the above problem will occur.

Because after a night, when I woke up in the morning, I only found that wsl2 had been restarted this one question

No other special circumstances were found​:joy::joy::joy::joy::joy:

This sounds very hard to believe that this would be the cause. I don’t have a WSL to test on, so it’s hard for me to verify, but can you reproduce this if you try again? Because my first instinct is to say that the password could be wrong, e.g. through a changed keyboard layout or with caps lock

There is always identity.pem.encrypted for every single new identity except for the *default that is created automatically.

What happens if you create an identity with --storage-mode plaintext?

@ic_axb I get this error when piping yes yes | to the dfx install command with an encrypted identity. The reason is that each prompt for yes/no is followed by another prompt to enter the password. Since the password is not entered in this case, it errors. It would be nice if the password could be entered only once at the beginning of a script, but I’m not sure how that could work.