This secret cannot be used for encryption

I am trying to encrypt / decrypt a text as described here: Anvil Docs | Encrypting Secret Data

These are the steps I have tried:

  • Created a new secret called “new_secret”
  • Clicked on “Generate Value” to automatically assign a new value
  • Started a new server console
  • Executed import anvil.secrets
  • Executed anvil.secrets.encrypt_with_key('new_secret', 'something')
  • Got the error anvil.secrets.SecretError: This secret cannot be used for encryption

image

What am I doing wrong?

I just tried the same thing, having never used it before either, the only thing that worked was “Create new key” but you do not get to choose the value for the key, just the name.
You can then call the name of the key in
anvil.secrets.encrypt_with_key('new_key', 'something')

image

I don’t know enough about it to know if thats how its supposed to work

1 Like

Oh, there are two sections: Secrets and Encryption Keys, duh!!!

All I needed to do was to create a new key, not a new secret.

I only noticed it after looking at your snapshot, not after trying 10 times in 2 different apps in the IDE.
Sadness!

Don’t worry, I first spent 10 minutes looking at the secrets clojure code in the anvil-runtime repo instead of just looking for button number 2
:melting_face:

3 Likes