question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Encrypt/Decrypt Endpoints not working for Symmetric Key

See original GitHub issue

I have setup a simple project using Spring Cloud Config Server and I’m trying to simply encrypt and decrypt some values. I create the project as a Spring Starter Project using the following pom.xml with Spring Boot.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.oreilly.cloud</groupId>
    <artifactId>spring-microservices-config-server6</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>spring-microservices-config-server6</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

From there I modify the main Spring Boot Application class to add the @EnableConfigServer annotation as follows:

@SpringBootApplication
@EnableConfigServer
public class SpringMicroservicesConfigServer6Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringMicroservicesConfigServer6Application.class, args);
    }
}

Within my application.properties file, I point to a git repository, setup the server port and enable symmetric key encryption using encrypt.key as follows:


server.port=8888
spring.cloud.config.server.git.uri=C:/Users/training/Desktop/sts-workspace/configuration
encrypt.key=secret

Next I open a bash shell and encrypt some data:

$ curl http://localhost:8888/encrypt -d Kevin

Which produces the value:

315ca5592635e4f65e0a0278cd08f74b5cef27e8379bd0e0d81d08c9ed8fbac161d

If I attempt to decrypt the value using:

curl localhost:8888/decrypt --data-urlencode 315ca5592635e4f65e0a0278cd08f74b5cef27e8379bd0e0d81d08c9ed8fbac161d

I receive the following error:

276{"description":"Text not encrypted with this key","status":"INVALID"}

I do not understand why this simple example does not work. I have confirmed my JCE extension is in place using some simple code to test the .jar files are in place. Is this an issue or am I missing something?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
spencergibbcommented, Nov 23, 2016

I won’t shame you, happens all the time. How about a good LOL 😆 and we call it good.

0reactions
repos-jmpcommented, Jun 27, 2017

Apologies if I sounded rude. Have submitted the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cloud Config — Encryption and Decryption at Rest
The Config Server can use a symmetric (shared) key or an asymmetric one (RSA key pair). In this story we use both the...
Read more >
Spring config server security encryption and decryption not ...
With spring cloud config server 2, we get an error response for endpoint /encrypt as The encryption algorithm is not strong enough.
Read more >
Problem trying to decrypt a share | Endpoint Encryption
I am Having a problem trying to decrypt a share. I get the message. This object was encrypted to the following public key(s):....
Read more >
Spring Cloud Config – Symmetric Encryption and Decryption
In this tutorial, you will learn how to encrypt and decrypt a property value that is being served by Spring Cloud Config Server....
Read more >
Spring Cloud Config Server - Symmetric Encryption ... - YouTube
Spring Cloud Config Server - Symmetric Encryption and Decryption. Watch later. Share. Copy link. Info. Shopping. Tap to unmute.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found