Skip to content

Commit a843e2b

Browse files
committed
update
1 parent 3e8673a commit a843e2b

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sonarlint.connectedMode.project": {
3+
"connectionId": "devsecops-appsec",
4+
"projectKey": "DevSecOps-AppSec_RSAEncryptionServiceJava"
5+
}
6+
}

pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.example</groupId>
6+
<artifactId>rsaservice</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>RSABackendService</name>
11+
<description>RSA Backend Service using Spring Boot</description>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>3.0.5</version>
17+
<relativePath/> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<properties>
21+
<java.version>17</java.version>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-web</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-test</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
</dependencies>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-maven-plugin</artifactId>
41+
</plugin>
42+
</plugins>
43+
</build>
44+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
package com.example.rsaservice.controller;
3+
4+
import com.example.rsaservice.util.RSAUtil;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
@RestController
12+
@RequestMapping("/api")
13+
public class RSAController {
14+
15+
@PostMapping("/encrypt")
16+
public ResponseEntity<Map<String, String>> encrypt(@RequestBody Map<String, String> request) {
17+
try {
18+
String plaintext = request.get("plaintext");
19+
String encryptedText = RSAUtil.encrypt(plaintext);
20+
Map<String, String> response = new HashMap<>();
21+
response.put("encryptedText", encryptedText);
22+
return ResponseEntity.ok(response);
23+
} catch (Exception e) {
24+
return ResponseEntity.status(500).body(Map.of("error", "Encryption failed: " + e.getMessage()));
25+
}
26+
}
27+
28+
@PostMapping("/decrypt")
29+
public ResponseEntity<Map<String, String>> decrypt(@RequestBody Map<String, String> request) {
30+
try {
31+
String encryptedText = request.get("encryptedText");
32+
String decryptedText = RSAUtil.decrypt(encryptedText);
33+
Map<String, String> response = new HashMap<>();
34+
response.put("decryptedText", decryptedText);
35+
return ResponseEntity.ok(response);
36+
} catch (Exception e) {
37+
return ResponseEntity.status(500).body(Map.of("error", "Decryption failed: " + e.getMessage()));
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)