Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ekpayencryption
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zahid Hassan
ekpayencryption
Commits
e667b0fd
Commit
e667b0fd
authored
Nov 29, 2023
by
Zahid Hassan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ekpay encryption service done
parent
9eb439a9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
155 additions
and
41 deletions
+155
-41
pom.xml
pom.xml
+50
-40
EncryptionController.java
.../gov/ekpayencryption/controller/EncryptionController.java
+26
-0
ResponseDto.java
src/main/java/bd/gov/ekpayencryption/dto/ResponseDto.java
+15
-0
ResponseStatusEnum.java
...n/java/bd/gov/ekpayencryption/dto/ResponseStatusEnum.java
+5
-0
EncryptionDecryptionService.java
.../ekpayencryption/service/EncryptionDecryptionService.java
+56
-0
application.properties
src/main/resources/application.properties
+0
-1
application.yml
src/main/resources/application.yml
+3
-0
No files found.
pom.xml
View file @
e667b0fd
<?xml version="1.0" encoding="UTF-8"?>
<?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"
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.7.17
</version>
<version>
2.7.17
</version>
<relativePath/>
<!-- lookup parent from repository -->
<relativePath/>
<!-- lookup parent from repository -->
</parent>
</parent>
<groupId>
bd.gov
</groupId>
<groupId>
bd.gov
</groupId>
<artifactId>
ekpayencryption
</artifactId>
<artifactId>
ekpayencryption
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<version>
0.0.1-SNAPSHOT
</version>
<name>
ekpayencryption
</name>
<name>
ekpayencryption
</name>
<description>
Ekpay Encryption Decryption Service
</description>
<description>
Ekpay Encryption Decryption Service
</description>
<properties>
<properties>
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springdoc
</groupId>
<groupId>
org.springdoc
</groupId>
<artifactId>
springdoc-openapi-ui
</artifactId>
<artifactId>
springdoc-openapi-ui
</artifactId>
<version>
1.6.15
</version>
<version>
1.6.15
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.nimbusds
</groupId>
<artifactId>
nimbus-jose-jwt
</artifactId>
<version>
9.30.2
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
</dependencies>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
</dependencies>
<build>
<build>
<plugins>
<finalName>
ekpayencryption
</finalName>
<plugin>
<plugins>
<groupId>
org.springframework.boot
</groupId>
<plugin>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<groupId>
org.springframework.boot
</groupId>
</plugin>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugins>
</plugin>
</build>
</plugins>
</build>
</project>
</project>
src/main/java/bd/gov/ekpayencryption/controller/EncryptionController.java
0 → 100644
View file @
e667b0fd
package
bd
.
gov
.
ekpayencryption
.
controller
;
import
bd.gov.ekpayencryption.dto.ResponseDto
;
import
bd.gov.ekpayencryption.dto.ResponseStatusEnum
;
import
bd.gov.ekpayencryption.service.EncryptionDecryptionService
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
public
class
EncryptionController
{
@PostMapping
(
value
=
"/encrypt"
)
public
ResponseEntity
<
String
>
encryptData
(
@RequestParam
String
secretKey
,
@RequestBody
String
plainText
)
{
String
response
=
EncryptionDecryptionService
.
encrypt
(
plainText
,
secretKey
);
return
ResponseEntity
.
ok
(
response
);
}
@PostMapping
(
value
=
"/decrypt"
)
public
ResponseEntity
<
String
>
decryptData
(
@RequestParam
String
secretKey
,
@RequestBody
String
cipherText
)
{
String
response
=
EncryptionDecryptionService
.
decrypt
(
cipherText
,
secretKey
);
return
ResponseEntity
.
ok
(
response
);
}
}
src/main/java/bd/gov/ekpayencryption/dto/ResponseDto.java
0 → 100644
View file @
e667b0fd
package
bd
.
gov
.
ekpayencryption
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public
class
ResponseDto
{
private
ResponseStatusEnum
status
;
private
String
data
;
}
src/main/java/bd/gov/ekpayencryption/dto/ResponseStatusEnum.java
0 → 100644
View file @
e667b0fd
package
bd
.
gov
.
ekpayencryption
.
dto
;
public
enum
ResponseStatusEnum
{
SUCCESS
,
FAILED
}
src/main/java/bd/gov/ekpayencryption/service/EncryptionDecryptionService.java
0 → 100644
View file @
e667b0fd
package
bd
.
gov
.
ekpayencryption
.
service
;
import
com.nimbusds.jose.*
;
import
com.nimbusds.jose.crypto.DirectDecrypter
;
import
com.nimbusds.jose.crypto.DirectEncrypter
;
import
com.nimbusds.jose.crypto.MACSigner
;
import
com.nimbusds.jwt.EncryptedJWT
;
import
com.nimbusds.jwt.JWTClaimsSet
;
import
com.nimbusds.jwt.JWTParser
;
import
com.nimbusds.jwt.SignedJWT
;
import
java.util.Date
;
public
interface
EncryptionDecryptionService
{
static
String
decrypt
(
String
cipherText
,
String
sKey
)
{
EncryptedJWT
encryptedJWT
;
try
{
encryptedJWT
=
(
EncryptedJWT
)
JWTParser
.
parse
(
cipherText
);
if
(
encryptedJWT
.
getState
().
equals
(
JWEObject
.
State
.
ENCRYPTED
))
{
encryptedJWT
.
decrypt
(
new
DirectDecrypter
(
sKey
.
getBytes
()));
return
encryptedJWT
.
getJWTClaimsSet
().
getStringClaim
(
"pyld"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
static
String
encrypt
(
String
plainText
,
String
sKey
)
{
String
cipherText
=
null
;
JWTClaimsSet
claims
=
new
JWTClaimsSet
.
Builder
()
.
subject
(
"prtnr/tkn"
)
.
issueTime
(
new
Date
())
.
expirationTime
(
new
Date
())
.
claim
(
"pyld"
,
plainText
)
.
build
();
try
{
JWSSigner
signer
=
new
MACSigner
(
sKey
.
getBytes
());
SignedJWT
signedToken
=
new
SignedJWT
(
new
JWSHeader
(
JWSAlgorithm
.
HS256
),
claims
);
signedToken
.
sign
(
signer
);
JWEHeader
jweHeader
=
new
JWEHeader
.
Builder
(
JWEAlgorithm
.
DIR
,
EncryptionMethod
.
A256GCM
).
contentType
(
"JWT"
).
build
();
JWEObject
jweObject
=
new
JWEObject
(
jweHeader
,
signedToken
.
getPayload
());
jweObject
.
encrypt
(
new
DirectEncrypter
(
sKey
.
getBytes
()));
cipherText
=
jweObject
.
serialize
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
cipherText
;
}
}
src/main/resources/application.properties
deleted
100644 → 0
View file @
9eb439a9
src/main/resources/application.yml
0 → 100644
View file @
e667b0fd
server
:
servlet
:
context-path
:
/ekpayencryption
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment