JCE error when trying to encrypt using Spring Security endpoint
search cancel

JCE error when trying to encrypt using Spring Security endpoint

book

Article ID: 297457

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

This article discusses how to fix a Java Cryptography Extension (JCE) error when trying to encrypt using Spring Security endpoint. The JCE error is causing the customer to be unable to encrypt and decrypt.

The following error message is displayed when trying to use encrypt or decrypt using the Spring Boot Security endpoint /encrypt or /decrypt.
{"timestamp":"2019-06-13T18:54:41.428+0000","status":500,"error":"Internal Server Error","message":"Unable to initialize due to invalid secret key","path":"/encrypt/"}


Cause

The application is not using the OpenJDK buildpack or a buildpack that includes a JCE package.

For example, if the application picks the Oracle JDK buildpack, Oracle JDK will not include the JCE package by default. You will see a JCE error message like the following:
{"timestamp":"2019-06-13T18:54:41.428+0000","status":500,"error":"Internal Server Error","message":"Unable to initialize due to invalid secret key","path":"/encrypt/"}

Resolution

Ensure that theĀ application is using the buildpack that includes the JCE package. The following command will show which buildpack the application is using:
  • run cf app <app name>
If it is using the incorrect buildpack you can attempt any of the following options:
  • Delete or disable the incorrect buildpack
    • cf update-buildpack BUILDPACK [-p PATH] [-i POSITION] [-s STACK] [--enable|--disable] [--lock|--unlock]
    • cf delete-buildpack BUILDPACK [-s STACK] [-f]
  • Give the correct buildpack a higher priority by modifying the -i POSITION
    • cf update-buildpack BUILDPACK [-p PATH] [-i POSITION] [-s STACK] [--enable|--disable] [--lock|--unlock]