Skip to content

Commit

Permalink
feat: smc PasswordField 数据切换为aes加密 (#257)
Browse files Browse the repository at this point in the history
des -> aes

Signed-off-by: unknowIfGuestInDream <tang97155@163.com>
  • Loading branch information
unknowIfGuestInDream committed Feb 6, 2023
1 parent 101ab1c commit 0d2cece
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
28 changes: 21 additions & 7 deletions core/src/test/java/com/tlcsdm/core/util/CryptoTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.tlcsdm.core.util;

import java.security.SecureRandom;

import javax.crypto.SecretKey;

import org.junit.jupiter.api.Test;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.KeyUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.DES;
import org.junit.jupiter.api.Test;

import javax.crypto.SecretKey;
import java.security.SecureRandom;

/**
* @author: unknowIfGuestInDream
Expand All @@ -24,7 +24,7 @@ public void md5() {
}

@Test
public void aes() {
public void aes1() {
final SecureRandom random = RandomUtil.getSecureRandom("123456".getBytes());
final SecretKey secretKey = KeyUtil.generateKey("AES", 128, random);

Expand All @@ -50,4 +50,18 @@ public void des() {
System.out.println(result);
}

/**
* aes
*/
@Test
public void aes() {
// AES aes = new AES(Mode.valueOf(Mode.ECB.name()), Padding.PKCS5Padding,
// HexUtil.decodeHex("0102030405060708090a0b0c0d0e0f10"));
AES aes = new AES(Mode.ECB, Padding.PKCS5Padding,
"3f4eefd3525675154a5e3a0183d8087b".getBytes());
String encryptStr = aes.encryptHex("16c5");
System.out.println(encryptStr);
System.out.println(aes.decryptStr(encryptStr));
}

}
8 changes: 4 additions & 4 deletions demo/src/main/java/com/tlcsdm/demo/ControlsFXSample.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.tlcsdm.demo;

import com.tlcsdm.demo.samples.Utils;
import com.tlcsdm.frame.SampleBase;

import java.io.IOException;
import java.io.InputStream;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import com.tlcsdm.demo.samples.Utils;
import com.tlcsdm.frame.SampleBase;

public abstract class ControlsFXSample extends SampleBase {

// 项目信息
Expand Down Expand Up @@ -60,7 +60,7 @@ public String getControlStylesheetURL() {

@Override
protected void initializeUserData() {
// do nothing
// Do nothing
}

/**
Expand Down
45 changes: 19 additions & 26 deletions frame/src/main/java/com/tlcsdm/frame/SampleBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,31 @@
*/
package com.tlcsdm.frame;

import java.io.File;
import java.time.LocalDate;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import com.tlcsdm.core.javafx.util.FxXmlUtil;
import com.tlcsdm.frame.util.I18nUtils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.DES;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Separator;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextInputControl;
import javafx.scene.control.*;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextFlow;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.File;
import java.time.LocalDate;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;

/**
* A base class for samples - it is recommended that they extend this class
* rather than Application, as then the samples can be run either standalone or
Expand Down Expand Up @@ -160,8 +153,8 @@ protected void initializeUserData() {
}
} else if (value instanceof PasswordField v) {
if (!StrUtil.isEmpty(val)) {
DES des = SecureUtil.des(aesSeed.getBytes());
v.setText(des.decryptStr(val));
AES aes = new AES(Mode.ECB, Padding.PKCS5Padding, aesSeed.getBytes());
v.setText(aes.decryptStr(val));
}
} else if (value instanceof TextInputControl v) {
if (!StrUtil.isEmpty(val)) {
Expand All @@ -176,7 +169,7 @@ protected void initializeUserData() {
} else if (value instanceof String v) {
v = val;
} else {
// do nothing
// Do nothing
}
});
}
Expand All @@ -198,8 +191,8 @@ protected void bindUserData() {
} else if (value instanceof DirectoryChooser v) {
FxXmlUtil.set(k, v.getInitialDirectory());
} else if (value instanceof PasswordField v) {
DES des = SecureUtil.des(aesSeed.getBytes());
FxXmlUtil.set(k, des.encryptHex(v.getText()));
AES aes = new AES(Mode.ECB, Padding.PKCS5Padding, aesSeed.getBytes());
FxXmlUtil.set(k, aes.encryptHex(v.getText()));
} else if (value instanceof TextInputControl v) {
FxXmlUtil.set(k, v.getText());
} else if (value instanceof CheckBox v) {
Expand All @@ -209,7 +202,7 @@ protected void bindUserData() {
} else if (value instanceof String v) {
FxXmlUtil.set(k, v);
} else {
// do nothing
// Do nothing
}
});
}
Expand All @@ -218,7 +211,7 @@ protected void bindUserData() {
* 版本升级后初始化对用户数据的更新, 默认为不进行修改, 由各个组件自己实现
*/
protected void updateForVersionUpgrade() {
// do nothing
// Do nothing
}

protected String getSampleXmlPrefix() {
Expand Down

0 comments on commit 0d2cece

Please sign in to comment.