22
33import com .jfoenix .controls .JFXComboBox ;
44import com .jfoenix .controls .JFXTextArea ;
5+ import ffffffff0x .beryenigma .App .Controller .Encryption .Modern .HMAC .Modern_HMAC ;
6+ import ffffffff0x .beryenigma .App .Controller .Encryption .Modern .Hash .Modern_Hash ;
7+ import ffffffff0x .beryenigma .App .View .Viewobj .PopupSettingDoubleColumnView ;
8+ import ffffffff0x .beryenigma .App .View .Viewobj .PopupSettingNode ;
59import ffffffff0x .beryenigma .App .View .Viewobj .ViewControllerFileMode ;
10+ import ffffffff0x .beryenigma .Init .Init ;
611import ffffffff0x .beryenigma .Init .ViewInit ;
712import ffffffff0x .beryenigma .Kit .Utils .FileUtils ;
813import javafx .fxml .FXML ;
14+ import org .apache .commons .codec .binary .Base64 ;
15+ import org .apache .commons .codec .binary .Hex ;
16+
17+ import java .io .UnsupportedEncodingException ;
18+ import java .security .InvalidKeyException ;
19+ import java .security .NoSuchAlgorithmException ;
20+ import java .util .Arrays ;
21+ import java .util .List ;
22+ import java .util .Objects ;
923
1024public class HMACController extends ViewControllerFileMode {
1125 /**
1226 * JTA_dst1 :HEX result
1327 * JTA_dst :base64 result
1428 */
1529
16- @ FXML private JFXComboBox JCB_charset ;
30+ @ FXML private JFXComboBox JCB_charset = new JFXComboBox () ;
1731 @ FXML private JFXComboBox <String > JCB_HMACMode ;
1832 @ FXML private JFXTextArea JTA_HMACKey ;
1933
@@ -26,41 +40,48 @@ protected void initialize() {
2640
2741 @ Override
2842 public void ONClickConfirm () {
29- // super.ONClickConfirm();
30- // JTA_dst.setStyle("-fx-text-fill: black");
31- // JTA_dst1.setStyle("-fx-text-fill: black");
32- // try{
33- // String[] dst = new String[0];
34- // if(JTB_modeSelect.getText().equals(Init.languageResourceBundle.getString("TextMode"))){
35- // try {
36- // dst = hash(JTA_src.getText().getBytes(JCB_charset.getValue().toString()));
37- // } catch (UnsupportedEncodingException e) {
38- // e.printStackTrace();
39- // }
40- // }else{
41- // dst = hash(byteFile);
42- // fileEncodeEnd();
43- // }
44- // JTA_dst1.setText(dst[0]);
45- // JTA_dst.setText(dst[1]);
46- // }catch (Exception e){
47- // JTA_dst.setStyle("-fx-text-fill: red");
48- // JTA_dst1.setStyle("-fx-text-fill: red");
49- // JTA_dst.setText(e.getMessage());
50- // JTA_dst1.setText(e.getMessage());
51- // }
43+ super .ONClickConfirm ();
44+ JTA_dst .setStyle ("-fx-text-fill: black" );
45+ JTA_dst1 .setStyle ("-fx-text-fill: black" );
46+ try {
47+ String [] dst = new String [0 ];
48+ if (JTB_modeSelect .getText ().equals (Init .languageResourceBundle .getString ("TextMode" ))){
49+ try {
50+ dst = hmac (JTA_src .getText ().getBytes (JCB_charset .getValue ().toString ()),
51+ JTA_HMACKey .getText ().getBytes (JCB_charset .getValue ().toString ()));
52+ } catch (UnsupportedEncodingException e ) {
53+ e .printStackTrace ();
54+ }
55+ }else {
56+ dst = hmac (byteFile , JTA_HMACKey .getText ().getBytes (JCB_charset .getValue ().toString ()));
57+ fileEncodeEnd ();
58+ }
59+ JTA_dst1 .setText (dst [0 ]);
60+ JTA_dst .setText (dst [1 ]);
61+ }catch (Exception e ){
62+ JTA_dst .setStyle ("-fx-text-fill: red" );
63+ JTA_dst1 .setStyle ("-fx-text-fill: red" );
64+ JTA_dst .setText (e .getMessage ());
65+ JTA_dst1 .setText (e .getMessage ());
66+ }
5267 }
5368
5469 private void initComboBox (){
5570 ViewInit .comboBoxCharset (JCB_charset );
56-
71+ JCB_HMACMode .getItems ().addAll (getInstanceNameList ());
72+ JCB_HMACMode .setValue ("HMACMD5" );
73+ JCB_HMACMode .setVisibleRowCount (6 );
5774
5875 }
5976
60- private String [] hash (byte [] message ){
61- return null ;
77+ private String [] hmac (byte [] data , byte [] key ) throws NoSuchAlgorithmException , InvalidKeyException {
78+ String [] out = new String [2 ];
79+ out [0 ] = Hex .encodeHexString (Objects .requireNonNull (Modern_HMAC .encryptHMAC (data ,
80+ key , JCB_HMACMode .getValue ())));
81+ out [1 ] = Base64 .encodeBase64String (Objects .requireNonNull (Modern_HMAC .encryptHMAC (data ,
82+ key , JCB_HMACMode .getValue ())));
83+ return out ;
6284 }
63-
6485 @ Override
6586 public void getFile (){
6687 super .getFile ();
@@ -72,4 +93,73 @@ protected void JTADSTContextMenu() {
7293 super .JTADSTContextMenu ();
7394 ViewInit .textAreaContextMenu (JTA_dst1 ,JTA_src );
7495 }
96+
97+ public List <String > getInstanceNameList () {
98+ List <String > result = Arrays .asList ("HMACMD2" ,
99+ "HMACMD4" ,
100+ "HMACMD5" ,
101+ "HMACSM3" ,
102+ "HMACSHA1" ,
103+ "HMACSHA224" ,
104+ "HMACSHA256" ,
105+ "HMACSHA3-224" ,
106+ "HMACSHA3-256" ,
107+ "HMACSHA3-384" ,
108+ "HMACSHA3-512" ,
109+ "HMACSHA384" ,
110+ "HMACSHA512" ,
111+ "HMACSHA512/224" ,
112+ "HMACSHA512/256" ,
113+ "HMACPBESHA1" ,
114+ "HMACPBESHA224" ,
115+ "HMACPBESHA256" ,
116+ "HMACPBESHA384" ,
117+ "HMACPBESHA512" ,
118+ "HMACPBESHA512/224" ,
119+ "HMACPBESHA512/256" ,
120+ "HMACRIPEMD128" ,
121+ "HMACRIPEMD160" ,
122+ "HMACRIPEMD256" ,
123+ "HMACRIPEMD320" ,
124+ "HMACSKEIN-1024-1024" ,
125+ "HMACSKEIN-1024-384" ,
126+ "HMACSKEIN-1024-512" ,
127+ "HMACSKEIN-256-128" ,
128+ "HMACSKEIN-256-160" ,
129+ "HMACSKEIN-256-224" ,
130+ "HMACSKEIN-256-256" ,
131+ "HMACSKEIN-512-128" ,
132+ "HMACSKEIN-512-160" ,
133+ "HMACSKEIN-512-224" ,
134+ "HMACSKEIN-512-256" ,
135+ "HMACSKEIN-512-384" ,
136+ "HMACSKEIN-512-512" ,
137+ "HMACDSTU7564-256" ,
138+ "HMACDSTU7564-384" ,
139+ "HMACDSTU7564-512" ,
140+ "HMACGOST3411" ,
141+ "HMACGOST3411-2012-256" ,
142+ "HMACGOST3411-2012-512" ,
143+ "HMACKECCAK224" ,
144+ "HMACKECCAK256" ,
145+ "HMACKECCAK288" ,
146+ "HMACKECCAK384" ,
147+ "HMACKECCAK512" ,
148+ "HMACTIGER" ,
149+ "HMACWHIRLPOOL" ,
150+ "OLDHMACSHA384" ,
151+ "OLDHMACSHA512" );
152+ return result ;
153+ }
154+
155+ @ Override
156+ protected void LoadPopupSettingNode () {
157+ super .LoadPopupSettingNode ();
158+
159+ //弹出式控件框
160+ PopupSettingDoubleColumnView popupSettingView = new PopupSettingDoubleColumnView (ACP_controllerAnchorPane );
161+
162+ //弹出式控件框中添加初始化的控件
163+ popupSettingView .setSetting (new PopupSettingNode (Init .languageResourceBundle .getString ("Charset" ),JCB_charset ,true ));
164+ }
75165}
0 commit comments