encript
This commit is contained in:
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.flagnote.note.entity.Note;
|
import com.flagnote.note.entity.Note;
|
||||||
import com.flagnote.note.repository.NoteMongoRepository;
|
import com.flagnote.note.repository.NoteMongoRepository;
|
||||||
import com.flagnote.note.utils.BizKeyUtils;
|
import com.flagnote.note.utils.BizKeyUtils;
|
||||||
|
import com.flagnote.note.utils.SecretUtils;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
@@ -40,8 +41,8 @@ public class NoteServiceImpl implements NoteService {
|
|||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
note.setTextBytes(SecretUtils.decodeNote(note.getTextBytes()));
|
||||||
return note;
|
return note;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,12 +52,13 @@ public class NoteServiceImpl implements NoteService {
|
|||||||
note.setId(mixKey);
|
note.setId(mixKey);
|
||||||
note.setKey(mixKey);
|
note.setKey(mixKey);
|
||||||
|
|
||||||
|
|
||||||
note.setExpireTime(DateUtil.offsetHour(note.getPushTime(), 1));
|
note.setExpireTime(DateUtil.offsetHour(note.getPushTime(), 1));
|
||||||
note.setRetentionTime(DateUtil.offsetSecond(note.getPushTime(), 400 * 3600));
|
note.setRetentionTime(DateUtil.offsetSecond(note.getPushTime(), 400 * 3600));
|
||||||
|
|
||||||
note.setState(1);
|
note.setState(1);
|
||||||
|
|
||||||
|
note.setTextBytes(SecretUtils.encodeNote(note.getTextBytes()));
|
||||||
|
|
||||||
noteMongoRepository.save(note);
|
noteMongoRepository.save(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,11 +67,10 @@ public class NoteServiceImpl implements NoteService {
|
|||||||
String mixKey = BizKeyUtils.mixKey(key);
|
String mixKey = BizKeyUtils.mixKey(key);
|
||||||
Note note = noteMongoRepository.findById(mixKey).orElse(null);
|
Note note = noteMongoRepository.findById(mixKey).orElse(null);
|
||||||
|
|
||||||
if(null!=note && ArrayUtil.isNotEmpty(note.getTextBytes())) {
|
if (null != note && ArrayUtil.isNotEmpty(note.getTextBytes())) {
|
||||||
note.setState(0);
|
note.setState(0);
|
||||||
note.setTextBytes(null);
|
note.setTextBytes(null);
|
||||||
noteMongoRepository.save(note);
|
noteMongoRepository.save(note);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main/java/com/flagnote/note/utils/SecretUtils.java
Normal file
21
src/main/java/com/flagnote/note/utils/SecretUtils.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package com.flagnote.note.utils;
|
||||||
|
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.Mode;
|
||||||
|
import cn.hutool.crypto.Padding;
|
||||||
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
|
|
||||||
|
public class SecretUtils {
|
||||||
|
|
||||||
|
private static AES aes = new AES(Mode.ECB, Padding.ZeroPadding,
|
||||||
|
new SecretKeySpec("b9t3pzbmybc66cba".getBytes(), "AES"));
|
||||||
|
|
||||||
|
public static byte[] encodeNote(byte[] text) {
|
||||||
|
return aes.encrypt(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] decodeNote(byte[] text) {
|
||||||
|
return aes.decrypt(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user