AES encryption

Secure Bitbucket configuration properties

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

In this method, you’ll use AlgorithmCipher that allows you to choose the algorithm used to encrypt the sensitive information in the file.

Before you begin: Prepare the JSON object

You’ll need to provide all arguments required to encrypt the sensitive data in a JSON object. Prepare beforehand by using the information and examples below.

plainTextPasswordPassword in plain text.

You can choose one of the following algorithms:

  • AES/CBC/PKCS5Padding
  • DES/CBC/PKCS5Padding
  • DESede/CBC/PKCS5Padding

The algorithm key must correspond with the algorithm chosen above:

  • AES
  • DES
  • DESede

See a sample JSON object

Step 1. Encrypt the sensitive data

Let's look at an example of encrypting your database password.

  1. Go to <Bitbucket-installation-directory>/tools/atlassian-password.

  2. Run the following command to encrypt your password:

    java -cp "./*" -c com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher
    See optional arguments
    • -- silent -s: limits logging to a minimum

    • -- help -h: prints a help message with all parameters

    • -- mode -m: defines what to do with the password, either encrypt or decrypt. If omitted, 'encrypt' will be used.

    • -- password -p: JSON object with required arguments. If omitted, you'll be asked to enter a password. We recommend that you omit this parameter so that your password is not stored in the terminal history.

  3. After running the command, you'll be asked to provide the required arguments in a JSON object in a single line. Prepare it based on the information from Before you begin.

When encrypting your data, the encryption tool generates three files and prints the output JSON object that you'll later add to the file. The next step discusses how to secure those files. 

Step 2. Secure the generated files

Change the permissions on the files generated by the tool so that they are read-only to the user running Bitbucket. Note that if a multi-node cluster is in use, then the files should be available on the same path for all nodes. Bitbucket needs the encrypted property to configure cluster-wide settings such as the database password.

The following files are generated:

  • javax.crypto.SealedObject_[timestamp]
    File with the encrypted password.

  • javax.crypto.spec.SecretKeySpec_[timestamp] 
    Key used to encrypt your password. You will need this file to decrypt your password.

    Algorithm parameters used to encrypt your password. You will need this file only if you want to recreate an encrypted password

Step 3. (Optional) Store file paths as environment variables

This step is optional and is only applicable if you're on a version below 8.11

This step is optional. You can store paths to the generated files as environment variables. If the paths aren't present in the file and the jdbc.password is an empty JSON object ({}), AlgorithmCipher will look for them in the environment. This way, file paths are not stored in the file, making it difficult to locate the files used for encryption.

  1. Store the two generated files as environment variables. You don't need to add the file with algorithm parameters, because AlgorithmCipher does not use it to decrypt the password. You must set the following environment variables to the correct values in any of the scripts used for launching your Bitbucket instance:

  2. Edit the output from the first step, Encrypt the password, and remove paths to the files. The decrypter class name and password should match the following:


Step 4. Add the encrypted data to

  1. Go to the Bitbucket home directory and back up the file. Move the backup to a safe place, ideally outside your instance.

  2. Based on your Bitbucket version, do one of the following:
    1. For versions on 8.11+, in the file, replace the application property with the output JSON object with {ENC} prefixed to the value. The properties should look like the following:  


    2. For versions below 8.11,  in the file, replace the jdbc.password property with the output JSON object. Depending on whether you’re using environment variables or not, adjust the JSON object to one of the following examples:

      1. If you’re storing file paths as environment variables, remove the paths from the output. The properties should look like the following:

      2. If you’re not using environment variables and want to stick to file paths in the file, make sure you update their paths after moving them to a secure place. The properties should look like the following: If you’re not using environment variables and want to stick to file paths in the file, make sure you update their paths after moving them to a secure place. The properties should look like the following: 

  3. Restart Bitbucket.

Decrypt the sensitive data

To decrypt the sensitive data, extend the command used earlier with the -m decrypt parameter:

java -cp "./*" -c com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher -m decrypt

When asked for a password, based on your Bitbucket version, do one of the following:

  • For versions on 8.11+provide the JSON object from your file without the {ENC} prefix. 


  • For versions below 8.11provide the JSON object from your file. 

    Sample JSON object when using file paths

Recreate encrypted data

Let's look at an example of recreating encrypted database password.

If you lose an encrypted password and try to encrypt the plain text password once again, the new encrypted password will look different. This is not an issue, as it will still represent the same plain text password. However, in some cases, you might want to keep it consistent, for example by having the same encrypted password when a Bitbucket instance is migrated to another server.

To encrypt the password in the exact same way as you did before, you will need the key used to encrypt the original password and the algorithm parameters. Both of these were generated by the encryption tool and saved in the following files:

  • Key: javax.crypto.spec.SecretKeySpec_[timestamp]
  • Algorithm parameters:[timestamp]

Once you've located these files, you can point the encryption tool to their location by using two extra fields in the JSON object. 


Path to a file that contains the key used to encrypt your original password, e.g. javax.crypto.spec.SecretKeySpec_[timestamp].

If you stored the file path as environment variable, you can omit this parameter.


Path to a file that contains the algorithm parameters used to encrypt your original password, e.g.[timestamp].

See a sample JSON object with all fields
{"plainTextPassword":"yourPassword", "algorithm":"AES/CBC/PKCS5PADDING", "algorithmKey":"AES", "algorithmParametersFilePath":"", "keyFilePath":"javax.crypto.spec.SecretKeySpec_123456789"}

To encrypt the password, follow the steps in the first step, Encrypt the password, and use the JSON object with the key and algorithm parameters.


Bitbucket fails to start after enabling database password encryption...

This means that Bitbucket couldn't connect to the database to access your configuration, most probably because of an error with decrypting your password.

To solve this problem, open <Bitbucket_home_directory>/log/atlassian-bitbucket.log, and check for DataSourcePasswordDecryptionException

For example:

com.atlassian.stash.internal.jdbc.DatasourcePasswordDecryptionException: java.lang.IllegalArgumentException: <>

This exception contains details about the error. If the error is java.lang.IllegalArgumentException, you will need to encrypt the password again. 

  • If the error is related to missing files, there might be a problem with your environment variables. They could have been deleted, or have not been set correctly. To verify that, try adding file paths to the JSON object in the file.

  • If you’re seeing some Bouncy Castle errors, you will need to encrypt the password again.

'A fatal error has occurred' message displayed after restarting Bitbucket...

To investigate this problem, open <Bitbucket_home_directory>/log/atlassian-bitbucket.log, and check for JdbcSQLExceptions. The messages should be pretty clear as to what went wrong.

You’ll likely see the following message:

 Wrong user name or password [28000-176]

This means that Bitbucket decrypted the password successfully, but the password itself is incorrect. You can verify that by completing these steps:

  1. Open the file, and copy the encrypted password.

  2. Decrypt the password.

  3. Check if the decrypted password is the same as the one in your backup file.

Disable database password encryption and revert changes...

To disable database password encryption, remove the jdbc.password.decrypter.classname property from the file, and change the encrypted password to the plain text one.

Last modified on Jul 11, 2024

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.