2023年5月6日18:26:37
parent
e2bde5f722
commit
437501f411
|
|
@ -562,4 +562,28 @@ public class CodecToolsController {
|
|||
public void maven_jar_install_menu_item(ActionEvent event) {
|
||||
load_small_tools(10);
|
||||
}
|
||||
|
||||
public void jks_file_menu_item(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void music_parser_menu_item(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void word_ocr_menu_item(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void bar_code_menu_item(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void pdf_menu_item(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void batch_update_file_name_menu_item(ActionEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,118 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import com.zhangmeng.tools.utils.AlertUtils;
|
||||
import com.zhangmeng.tools.utils.ImagePath;
|
||||
import com.zhangmeng.tools.utils.JksUtils;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-05-06 16:43
|
||||
*/
|
||||
public class JksFileController {
|
||||
|
||||
@FXML
|
||||
public TextField dir;
|
||||
|
||||
@FXML
|
||||
public Button choose_file;
|
||||
|
||||
|
||||
@FXML
|
||||
public Button x509_gen;
|
||||
|
||||
@FXML
|
||||
public TextField jks_file_name;
|
||||
|
||||
@FXML
|
||||
public TextField cer_file_name;
|
||||
|
||||
@FXML
|
||||
public Button jks_gen;
|
||||
|
||||
@FXML
|
||||
public TextArea jks_public;
|
||||
|
||||
@FXML
|
||||
public TextArea cer_public;
|
||||
|
||||
@FXML
|
||||
public TextArea jks_private;
|
||||
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
choose_file.setText(null);
|
||||
ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE)));
|
||||
iv.setPreserveRatio(true);
|
||||
iv.setFitWidth(18);
|
||||
choose_file.setGraphic(iv);
|
||||
|
||||
choose_file.setOnAction(event -> {
|
||||
Stage stage = new Stage();
|
||||
DirectoryChooser dc = new DirectoryChooser();
|
||||
dc.setTitle("文件夹选择器");
|
||||
File file = dc.showDialog(stage);
|
||||
if (file != null) {
|
||||
String path = file.getAbsolutePath();
|
||||
dir.setText(path);
|
||||
}
|
||||
});
|
||||
|
||||
x509_gen.setOnAction(event -> {
|
||||
|
||||
if (dir.getText().length() == 0) {
|
||||
AlertUtils.alert_warning("文件夹不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
String content = JksUtils.GetCertFile.x509Certificate(dir.getText());
|
||||
cer_public.setText(content);
|
||||
|
||||
});
|
||||
|
||||
jks_gen.setOnAction(event -> {
|
||||
|
||||
if (dir.getText().length() == 0) {
|
||||
AlertUtils.alert_warning("文件夹不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (jks_file_name.getText().length() == 0) {
|
||||
AlertUtils.alert_warning("jks文件名不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
JksUtils.GetJksAndCerFile.jks_cer(dir.getText() + jks_file_name.getText(), "123456", "123456", dir.getText() + cer_file_name.getText());
|
||||
Path path = Paths.get(dir.getText() + jks_file_name.getText());
|
||||
Path path2 = Paths.get(dir.getText() + cer_file_name.getText());
|
||||
|
||||
try {
|
||||
while (true){
|
||||
if (Files.exists(path) && Files.exists(path2)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JksUtils.GetJksAndCerFile.readJks(dir.getText() + jks_file_name.getText(), "123456");
|
||||
JksUtils.GetJksAndCerFile.readCer(dir.getText() + cer_file_name.getText());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,24 @@
|
|||
package com.zhangmeng.tools.utils;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
import org.bouncycastle.x509.X509V3CertificateGenerator;
|
||||
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.*;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
|
||||
|
|
@ -21,6 +27,7 @@ import java.util.Enumeration;
|
|||
* @version : 1.0
|
||||
* @date : 2023-04-23 09:17
|
||||
*/
|
||||
@Slf4j
|
||||
public class JksUtils {
|
||||
|
||||
public static class GetCertFile {
|
||||
|
|
@ -30,14 +37,25 @@ public class JksUtils {
|
|||
//证书使用者
|
||||
static String CertificateUser = "C=中国,ST=广东,L=广州,O=人民组织,OU=人民单位,CN=";
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static String x509Certificate(String dir){
|
||||
Path path = Paths.get(dir + file_name() + ".cer");
|
||||
try {
|
||||
X509Certificate cert = getCert();
|
||||
System.out.println(cert.toString());
|
||||
if (!Files.exists(path)){
|
||||
Files.createFile(path);
|
||||
}
|
||||
X509Certificate cert = getCert(path.toFile());
|
||||
return cert.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String file_name(){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
|
||||
/*
|
||||
* CN(Common Name名字与姓氏)
|
||||
* OU(Organization Unit组织单位名称)
|
||||
|
|
@ -45,8 +63,10 @@ public class JksUtils {
|
|||
* ST(State州或省份名称)
|
||||
* C(Country国家名称)
|
||||
* L(Locality城市或区域名称)
|
||||
*
|
||||
* "F:\\cer.cer"
|
||||
* */
|
||||
public static X509Certificate getCert() throws Exception {
|
||||
public static X509Certificate getCert(File file) throws Exception {
|
||||
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
|
||||
keyPairGenerator.initialize(1024);
|
||||
KeyPair keyPair = keyPairGenerator.generateKeyPair();
|
||||
|
|
@ -70,7 +90,7 @@ public class JksUtils {
|
|||
Security.addProvider(new BouncyCastleProvider());
|
||||
X509Certificate x509Certificate = x509V3CertificateGenerator.generateX509Certificate(keyPair.getPrivate(), "BC");
|
||||
//写入文件
|
||||
FileOutputStream fos = new FileOutputStream("F:\\cer.cer");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(x509Certificate.getEncoded());
|
||||
fos.flush();
|
||||
fos.close();
|
||||
|
|
@ -80,31 +100,33 @@ public class JksUtils {
|
|||
|
||||
public static class GetJksAndCerFile {
|
||||
|
||||
public static void main(String[] args) {
|
||||
buildKeyAndSaveToJksFile();
|
||||
exportCerFile();
|
||||
try {
|
||||
readJks();
|
||||
readCer();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static void jks_cer(String file,String keypass,String storepass,String cer_file) {
|
||||
buildKeyAndSaveToJksFile(file, keypass, storepass);
|
||||
exportCerFile(file,cer_file);
|
||||
// try {
|
||||
// readJks(file,keypass);
|
||||
// readCer(cer_file);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public static void executeCommand(String[] arstringCommand) {
|
||||
try {
|
||||
Runtime.getRuntime().exec(arstringCommand);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file //f:/demo.jks
|
||||
* @param keypass 123456
|
||||
* @param storepass 123456
|
||||
*/
|
||||
//生成密钥并保存到jks文件
|
||||
public static void buildKeyAndSaveToJksFile() {
|
||||
public static void buildKeyAndSaveToJksFile(String file,String keypass,String storepass) {
|
||||
String[] command = new String[]{
|
||||
"cmd ",
|
||||
"/k",
|
||||
|
|
@ -124,11 +146,11 @@ public class JksUtils {
|
|||
"-validity", // 有效天数
|
||||
"36500",
|
||||
"-keypass",// 密钥口令(私钥的密码)
|
||||
"123456",
|
||||
keypass,
|
||||
"-keystore", //密钥库名称(jks文件路径)
|
||||
"f:/demo.jks",
|
||||
file,
|
||||
"-storepass", // 密钥库口令(jks文件的密码)
|
||||
"123456",
|
||||
storepass,
|
||||
"-v"// 详细输出(秘钥库中证书的详细信息)
|
||||
};
|
||||
executeCommand(command);
|
||||
|
|
@ -136,7 +158,7 @@ public class JksUtils {
|
|||
|
||||
|
||||
//从jks文件中导出证书文件
|
||||
public static void exportCerFile() {
|
||||
public static void exportCerFile(String jks_file,String cer_file) {
|
||||
String[] command = new String[]{
|
||||
"cmd ", "/k",
|
||||
"start", // cmd Shell命令
|
||||
|
|
@ -146,43 +168,61 @@ public class JksUtils {
|
|||
"-alias", // -alias指定别名,这里是ss
|
||||
"sun",
|
||||
"-keystore", // -keystore指定keystore文件,这里是d:/demo.keystore
|
||||
"f:/demo.jks",
|
||||
jks_file,
|
||||
"-rfc",
|
||||
"-file",//-file指向导出路径
|
||||
"f:/demo.cer",
|
||||
cer_file,
|
||||
"-storepass",// 指定密钥库的密码
|
||||
"123456"
|
||||
};
|
||||
executeCommand(command);
|
||||
|
||||
}
|
||||
|
||||
public static class JKSInfo{
|
||||
private String private_key;
|
||||
private String public_key;
|
||||
|
||||
public String getPrivate_key() {
|
||||
return private_key;
|
||||
}
|
||||
|
||||
public void setPrivate_key(String private_key) {
|
||||
this.private_key = private_key;
|
||||
}
|
||||
|
||||
public String getPublic_key() {
|
||||
return public_key;
|
||||
}
|
||||
|
||||
public void setPublic_key(String public_key) {
|
||||
this.public_key = public_key;
|
||||
}
|
||||
}
|
||||
|
||||
//读取jks文件获取公、私钥
|
||||
public static void readJks() throws Exception {
|
||||
public static void readJks(String file,String keypass) throws Exception {
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(new FileInputStream("f:\\demo.jks"), "123456".toCharArray());
|
||||
keyStore.load(new FileInputStream(file), keypass.toCharArray());
|
||||
Enumeration<String> aliases = keyStore.aliases();
|
||||
String alias = null;
|
||||
while (aliases.hasMoreElements()) {
|
||||
alias = aliases.nextElement();
|
||||
}
|
||||
System.out.println("jks文件别名是:" + alias);
|
||||
log.info("jks文件别名是:" + alias);
|
||||
PrivateKey key = (PrivateKey) keyStore.getKey(alias, "123456".toCharArray());
|
||||
System.out.println("jks文件中的私钥是:" + new String(Base64.encode(key.getEncoded())));
|
||||
Certificate certificate = keyStore.getCertificate(alias);
|
||||
PublicKey publicKey = certificate.getPublicKey();
|
||||
System.out.println("jks文件中的公钥:" + new String(Base64.encode(publicKey.getEncoded())));
|
||||
log.info("jks文件中的公钥:" + new String(Base64.encode(publicKey.getEncoded())));
|
||||
}
|
||||
|
||||
|
||||
//读取证书文件获取公钥
|
||||
public static void readCer() throws Exception {
|
||||
public static void readCer(String file) throws Exception {
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
||||
Certificate certificate =
|
||||
certificateFactory.generateCertificate(new FileInputStream("f:\\demo.cer"));
|
||||
Certificate certificate = certificateFactory.generateCertificate(new FileInputStream(file));
|
||||
PublicKey publicKey = certificate.getPublicKey();
|
||||
System.out.println("证书中的公钥:" + new String(Base64.encode(publicKey.getEncoded())));
|
||||
log.info("证书中的公钥:" + new String(Base64.encode(publicKey.getEncoded())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class ResourcesUtils {
|
|||
public enum Menu {
|
||||
Md5("md5加密", 0),
|
||||
SpringSecurity("spring加密", 1),
|
||||
Jks_File("spring加密", 2),
|
||||
Jks_File("Jks_File", 2),
|
||||
;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@
|
|||
<Menu mnemonicParsing="false" text="加密工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#md5_menu_item" text="md5 加密"/>
|
||||
<MenuItem mnemonicParsing="false" onAction="#spring_security_menu_item"
|
||||
text="spring security 加密"/>
|
||||
<MenuItem mnemonicParsing="false" onAction="#spring_security_menu_item" text="spring security 加密"/>
|
||||
<MenuItem mnemonicParsing="false" onAction="#jks_file_menu_item" text="jkd 文件生成"/>
|
||||
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="影音工具">
|
||||
|
|
@ -24,6 +25,7 @@
|
|||
<MenuItem mnemonicParsing="false" text="视频播放" onAction="#video_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="音乐播放" onAction="#music_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="vip 视频解析" onAction="#vip_parser_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="音乐解析" onAction="#music_parser_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="常用小工具">
|
||||
|
|
@ -39,6 +41,10 @@
|
|||
<MenuItem mnemonicParsing="false" text="手机号工具" onAction="#telephone_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="JsonView" onAction="#JsonView_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="maven-jar-install" onAction="#maven_jar_install_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="word-ocr" onAction="#word_ocr_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="条形码识别" onAction="#bar_code_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="pdf识别" onAction="#pdf_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="批量修改文件名" onAction="#batch_update_file_name_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
|
||||
|
|
@ -51,10 +57,11 @@
|
|||
</items>
|
||||
</Menu>
|
||||
|
||||
<Menu mnemonicParsing="false" text="sql工具">
|
||||
<Menu mnemonicParsing="false" text="代码工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="mysql代码生成" onAction="#sql_code_gen_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="mybatis-plus 代码生成" onAction="#mybatis_plus_gen_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="json转javaBean 代码生成" onAction="#json_javabean_gen_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
|
||||
|
|
@ -72,6 +79,10 @@
|
|||
<MenuItem mnemonicParsing="false" text="ftp-server 请求工具" onAction="#ftp_server_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="ssh-client 请求工具" onAction="#ssh_client_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-server 服务工具" onAction="#socket_server_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-client-aio 客户端工具" onAction="#socket_client_aio_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-server-aio 服务端工具" onAction="#socket_server_aio_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-server-nio 服务端工具" onAction="#socket_server_nio_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-client-nio 客户端工具" onAction="#socket_client_nio_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
</menus>
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@
|
|||
<MenuItem mnemonicParsing="false" text="socket-client-aio 客户端工具" onAction="#socket_client_aio_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-server-aio 服务端工具" onAction="#socket_server_aio_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-server-nio 服务端工具" onAction="#socket_server_nio_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-client-nio 服务端工具" onAction="#socket_client_nio_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="socket-client-nio 客户端工具" onAction="#socket_client_nio_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
</menus>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextArea?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<AnchorPane prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.JksFileController">
|
||||
<children>
|
||||
<TextField fx:id="dir" layoutX="101.0" layoutY="18.0" prefHeight="25.0" prefWidth="474.0" />
|
||||
<Button fx:id="choose_file" layoutX="598.0" layoutY="18.0" mnemonicParsing="false" text="Button" />
|
||||
<TextArea fx:id="jks_public" layoutX="114.0" layoutY="110.0" prefHeight="170.0" prefWidth="1045.0" />
|
||||
<Button layoutX="1025.0" layoutY="18.0" mnemonicParsing="false" text="x509Certificate-生成" fx:id="x509_gen" />
|
||||
<Label layoutX="40.0" layoutY="22.0" text="生成路径:" />
|
||||
<Label layoutX="137.0" layoutY="458.0" />
|
||||
<Label layoutX="38.0" layoutY="73.0" text="jks文件名:" />
|
||||
<TextField fx:id="jks_file_name" layoutX="101.0" layoutY="69.0" />
|
||||
<TextField fx:id="cer_file_name" layoutX="365.0" layoutY="69.0" />
|
||||
<Label layoutX="293.0" layoutY="73.0" text="cer文件名:" />
|
||||
<TextArea fx:id="cer_public" layoutX="114.0" layoutY="483.0" prefHeight="143.0" prefWidth="1117.0" />
|
||||
<Button fx:id="jks_gen" layoutX="606.0" layoutY="69.0" mnemonicParsing="false" text="生成" />
|
||||
<Label layoutX="50.0" layoutY="117.0" text="JKS 公钥:" />
|
||||
<Label layoutX="41.0" layoutY="308.0" text="JKS 私钥:" />
|
||||
<TextArea fx:id="jks_private" layoutX="114.0" layoutY="308.0" prefHeight="143.0" prefWidth="1045.0" />
|
||||
<Label layoutX="50.0" layoutY="483.0" text="证书公钥:" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Loading…
Reference in New Issue