2023年5月6日18:26:37
parent
cb5236885f
commit
0000aab742
|
|
@ -12,6 +12,9 @@
|
|||
#### 1.2 spring security 加密
|
||||

|
||||
|
||||
#### 1.3 jks 文件生成
|
||||

|
||||
|
||||
|
||||
### 2. 影音工具
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
|
|
@ -11,11 +12,19 @@ import javafx.scene.image.Image;
|
|||
import javafx.scene.image.ImageView;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.Stage;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.KeyStore;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
|
|
@ -100,19 +109,68 @@ public class JksFileController {
|
|||
Path path = Paths.get(dir.getText() + jks_file_name.getText());
|
||||
Path path2 = Paths.get(dir.getText() + cer_file_name.getText());
|
||||
|
||||
try {
|
||||
new Thread(()->{
|
||||
while (true){
|
||||
if (Files.exists(path) && Files.exists(path2)){
|
||||
if (Files.exists(path)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JksUtils.GetJksAndCerFile.readJks(dir.getText() + jks_file_name.getText(), "123456");
|
||||
JksUtils.GetJksAndCerFile.readCer(dir.getText() + cer_file_name.getText());
|
||||
try {
|
||||
readJks(dir.getText() + jks_file_name.getText(), "123456");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}).start();
|
||||
|
||||
new Thread(()->{
|
||||
while (true){
|
||||
if (Files.exists(path2)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
readCer(dir.getText() + cer_file_name.getText());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}).start();
|
||||
|
||||
//&& Files.exists(path2)
|
||||
// JksUtils.GetJksAndCerFile.readJks(dir.getText() + jks_file_name.getText(), "123456");
|
||||
// JksUtils.GetJksAndCerFile.readCer(dir.getText() + cer_file_name.getText());
|
||||
});
|
||||
}
|
||||
|
||||
//读取证书文件获取公钥
|
||||
public void readCer(String file) throws Exception {
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
||||
Certificate certificate = certificateFactory.generateCertificate(new FileInputStream(file));
|
||||
PublicKey publicKey = certificate.getPublicKey();
|
||||
String cer = new String(Base64.encode(publicKey.getEncoded()));
|
||||
cer_public.setText(cer);
|
||||
}
|
||||
|
||||
//读取jks文件获取公、私钥
|
||||
public void readJks(String file,String keypass) throws Exception {
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(new FileInputStream(file), keypass.toCharArray());
|
||||
Enumeration<String> aliases = keyStore.aliases();
|
||||
String alias = null;
|
||||
while (aliases.hasMoreElements()) {
|
||||
alias = aliases.nextElement();
|
||||
}
|
||||
PrivateKey key = (PrivateKey) keyStore.getKey(alias, keypass.toCharArray());
|
||||
|
||||
Certificate certificate = keyStore.getCertificate(alias);
|
||||
PublicKey publicKey = certificate.getPublicKey();
|
||||
String jks_p = new String(Base64.encode(publicKey.getEncoded()));
|
||||
String private_key = new String(Base64.encode(key.getEncoded())) ;
|
||||
|
||||
Platform.runLater(()->{
|
||||
jks_private.setText(private_key);
|
||||
jks_public.setText(jks_p);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 73 KiB |
Loading…
Reference in New Issue