Skip to content

Commit

Permalink
feat: 편지 작성시 본문 내용 암호화하여 저장되도록 수정 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
623nana committed Aug 7, 2021
1 parent e07ac3c commit 5bd8b9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'commons-codec:commons-codec:1.15'
implementation 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nexters.covid.letter.api.dto;

import static org.springframework.beans.BeanUtils.copyProperties;
import static org.apache.commons.codec.binary.Base64.decodeBase64;

import com.nexters.covid.letter.domain.Letter;
import com.nexters.covid.letter.domain.State;
Expand Down Expand Up @@ -31,5 +32,10 @@ public class LetterResponse {

public LetterResponse(Letter source) {
copyProperties(source, this);
this.contents = decodeContents(source.getContents());
}

private String decodeContents(String contents) {
return new String(decodeBase64(contents));
}
}
8 changes: 7 additions & 1 deletion src/main/java/com/nexters/covid/letter/domain/Letter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexters.covid.letter.domain;

import static org.apache.commons.codec.binary.Base64.encodeBase64String;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nexters.covid.base.BaseEntity;
import com.nexters.covid.letter.api.dto.LetterRequest;
Expand Down Expand Up @@ -52,7 +54,7 @@ public Letter(LetterRequest request, User user) {
this.user = user;
this.letterTo = request.getEmail();
this.title = request.getTitle();
this.contents = request.getContents();
this.contents = encodeContents(request.getContents());
this.email = user.getEmail();
this.state = State.PENDING;
this.sticker = request.getSticker();
Expand All @@ -63,4 +65,8 @@ public Letter(LetterRequest request, User user) {
private String generateEncryptedId() {
return UUID.randomUUID().toString();
}

private String encodeContents(String contents) {
return encodeBase64String(contents.getBytes());
}
}

0 comments on commit 5bd8b9c

Please sign in to comment.