Skip to content

Commit

Permalink
Merge pull request #15 from shiker1996/feature-1.3.1
Browse files Browse the repository at this point in the history
improve plugin size and settings option
  • Loading branch information
shiker1996 authored Mar 31, 2024
2 parents 33075bd + 05cf0f3 commit 42f4951
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 680 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "tech.shiker"
version = "1.3.0"
version = "1.3.1"

repositories {
maven { url 'https://maven.aliyun.com/repository/central/' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tech.shiker.security;
package tech.shiker.common;

import java.nio.charset.StandardCharsets;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tech/shiker/common/SecurityConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ public class SecurityConstant {

public static final String KEY_NULL_MESSAGE = "Security key can't be null";

public static final String KEY_INVALID_MESSAGE = "Security key is invalid";
public static final String KEY_INVALID_MESSAGE = "Security key must be %s bytes long";

public static final String SALT_INVALID_MESSAGE = "Security salt must be at least 8 bytes long";

public static final String ITERATIONS_INVALID_MESSAGE = "Security iterations must be greater than 0";

public static final String IV_NULL_MESSAGE = "Security iv can't be null";

public static final String IV_INVALID_MESSAGE = "Security iv is invalid";
public static final String IV_INVALID_MESSAGE = "Security iv must be %s bytes long";

public static final String DECRYPT_ERR_MESSAGE = "Decrypt error:%s, err:%s";

Expand Down
80 changes: 80 additions & 0 deletions src/main/java/tech/shiker/common/SecurityInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package tech.shiker.common;

public enum SecurityInfo {

AES_ECB_PKCS5_PADDING("AES", "AES/ECB/PKCS5Padding", -1, 16, false),
AES_ECB_NO_PADDING("AES", "AES/ECB/NoPadding", -1, 16, true),
AES_CBC_PKCS5_PADDING("AES", "AES/CBC/PKCS5Padding", 16, 16, false),
AES_CBC_NO_PADDING("AES", "AES/CBC/NoPadding", 16, 16, true),
DES_ECB_PKCS5_PADDING("DESede", "DESede/ECB/PKCS5Padding", -1, 24, false),
DES_ECB_NO_PADDING("DESede", "DESede/ECB/NoPadding", -1, 24, true),
DES_CBC_PKCS5_PADDING("DESede", "DESede/CBC/PKCS5Padding", 8, 24, false),
DES_CBC_NO_PADDING("DESede", "DESede/CBC/NoPadding", 8, 24, true),
PBE_WITH_MD5_AND_DES("PBEWithMD5AndDES", "PBEWithMD5AndDES", -1, 8),
PBE_WITH_SHA1_AND_DES("PBEWithSHA1AndDESede", "PBEWithSHA1AndDESede", -1, 8),
PBE_WITH_SHA256_AND_AES_128("PBEWithHmacSHA256AndAES_128", "PBEWithHmacSHA256AndAES_128", 16, 8),
PBE_WITH_SHA512_AND_AES_256("PBEWithHmacSHA512AndAES_256", "PBEWithHmacSHA512AndAES_256", 16, 8),
;

private final String decryptType;

private final String decryptInformation;

private final int indexLength;

private final int keyLength;

private final int saltLength;

private final int iterations;

private final boolean handlePadding;

SecurityInfo(String decryptType, String decryptInformation, int indexLength, int keyLength, boolean handlePadding) {
this.decryptType = decryptType;
this.decryptInformation = decryptInformation;
this.indexLength = indexLength;
this.keyLength = keyLength;
this.saltLength = -1;
this.iterations = -1;
this.handlePadding = handlePadding;
}

SecurityInfo(String decryptType, String decryptInformation, int indexLength, int saltLength) {
this.decryptType = decryptType;
this.decryptInformation = decryptInformation;
this.indexLength = indexLength;
this.keyLength = -1;
this.saltLength = saltLength;
this.iterations = 0;
this.handlePadding = false;
}

public String decryptType() {
return decryptType;
}

public String decryptInformation() {
return decryptInformation;
}

public int indexLength() {
return indexLength;
}

public int keyLength() {
return keyLength;
}

public int saltLength() {
return saltLength;
}

public int iterations() {
return iterations;
}

public boolean handlePadding() {
return handlePadding;
}
}
70 changes: 30 additions & 40 deletions src/main/java/tech/shiker/common/SecurityMethod.java
Original file line number Diff line number Diff line change
@@ -1,72 +1,62 @@
package tech.shiker.common;

import com.google.common.collect.Lists;
import tech.shiker.security.AesCBCNoPaddingSecurityInstance;
import tech.shiker.security.AesCBCPkcs5PaddingSecurityInstance;
import tech.shiker.security.AesECBNoPaddingSecurityInstance;
import tech.shiker.security.AesECBPkcs5PaddingSecurityInstance;
import tech.shiker.security.DesCBCNoPaddingSecurityInstance;
import tech.shiker.security.DesCBCPkcs5PaddingSecurityInstance;
import tech.shiker.security.DesECBNoPaddingSecurityInstance;
import tech.shiker.security.DesECBPkcs5PaddingSecurityInstance;
import tech.shiker.security.PBEWithMD5AndDesSecurityInstance;
import tech.shiker.security.PBEWithSHA1AndDesSecurityInstance;
import tech.shiker.security.PBEWithSHA256AndAes128SecurityInstance;
import tech.shiker.security.PBEWithSHA512AndAes256SecurityInstance;
import tech.shiker.security.SecurityInstance;
import tech.shiker.security.impl.CBCSecurityInstance;
import tech.shiker.security.impl.ECBSecurityInstance;
import tech.shiker.security.impl.PBEWithAesSecurityInstance;
import tech.shiker.security.impl.PBEWithDesSecurityInstance;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum SecurityMethod {

AES_ECB_PKCS5_PADDING("AES", "AES/ECB/PKCS5Padding", new AesECBPkcs5PaddingSecurityInstance()),
AES_ECB_NO_PADDING("AES", "AES/ECB/NoPadding", new AesECBNoPaddingSecurityInstance()),
AES_CBC_PKCS5_PADDING("AES", "AES/CBC/PKCS5Padding", new AesCBCPkcs5PaddingSecurityInstance()),
AES_CBC_NO_PADDING("AES", "AES/CBC/NoPadding", new AesCBCNoPaddingSecurityInstance()),
DES_ECB_PKCS5_PADDING("DESede", "DESede/ECB/PKCS5Padding", new DesECBPkcs5PaddingSecurityInstance()),
DES_ECB_NO_PADDING("DESede", "DESede/ECB/NoPadding", new DesECBNoPaddingSecurityInstance()),
DES_CBC_PKCS5_PADDING("DESede", "DESede/CBC/PKCS5Padding", new DesCBCPkcs5PaddingSecurityInstance()),
DES_CBC_NO_PADDING("DESede", "DESede/CBC/NoPadding", new DesCBCNoPaddingSecurityInstance()),
PBE_WITH_MD5_AND_DES("PBEWithMD5AndDES", "PBEWithMD5AndDES", new PBEWithMD5AndDesSecurityInstance()),
PBE_WITH_SHA1_AND_DES("PBEWithSHA1AndDESede", "PBEWithSHA1AndDESede", new PBEWithSHA1AndDesSecurityInstance()),
PBE_WITH_SHA256_AND_AES_128("PBEWithHmacSHA256AndAES_128", "PBEWithHmacSHA256AndAES_128", new PBEWithSHA256AndAes128SecurityInstance()),
PBE_WITH_SHA512_AND_AES_256("PBEWithHmacSHA512AndAES_256", "PBEWithHmacSHA512AndAES_256", new PBEWithSHA512AndAes256SecurityInstance()),
AES_ECB_NO_PADDING(SecurityInfo.AES_ECB_NO_PADDING, new ECBSecurityInstance(SecurityInfo.AES_ECB_NO_PADDING)),
AES_ECB_PKCS5_PADDING(SecurityInfo.AES_ECB_PKCS5_PADDING, new ECBSecurityInstance(SecurityInfo.AES_ECB_PKCS5_PADDING)),
DES_ECB_NO_PADDING(SecurityInfo.DES_ECB_NO_PADDING, new ECBSecurityInstance(SecurityInfo.DES_ECB_NO_PADDING)),
DES_ECB_PKCS5_PADDING(SecurityInfo.DES_ECB_PKCS5_PADDING, new ECBSecurityInstance(SecurityInfo.DES_ECB_PKCS5_PADDING)),
AES_CBC_NO_PADDING(SecurityInfo.AES_CBC_NO_PADDING, new CBCSecurityInstance(SecurityInfo.AES_CBC_NO_PADDING)),
AES_CBC_PKCS5_PADDING(SecurityInfo.AES_CBC_PKCS5_PADDING, new CBCSecurityInstance(SecurityInfo.AES_CBC_PKCS5_PADDING)),
DES_CBC_NO_PADDING(SecurityInfo.DES_CBC_NO_PADDING, new CBCSecurityInstance(SecurityInfo.DES_CBC_NO_PADDING)),
DES_CBC_PKCS5_PADDING(SecurityInfo.DES_CBC_PKCS5_PADDING, new CBCSecurityInstance(SecurityInfo.DES_CBC_PKCS5_PADDING)),
PBE_WITH_MD5_AND_DES(SecurityInfo.PBE_WITH_MD5_AND_DES, new PBEWithDesSecurityInstance(SecurityInfo.PBE_WITH_MD5_AND_DES)),
PBE_WITH_SHA1_AND_DES(SecurityInfo.PBE_WITH_SHA1_AND_DES, new PBEWithDesSecurityInstance(SecurityInfo.PBE_WITH_SHA1_AND_DES)),
PBE_WITH_SHA256_AND_AES_128(SecurityInfo.PBE_WITH_SHA256_AND_AES_128, new PBEWithAesSecurityInstance(SecurityInfo.PBE_WITH_SHA256_AND_AES_128)),
PBE_WITH_SHA512_AND_AES_256(SecurityInfo.PBE_WITH_SHA512_AND_AES_256, new PBEWithAesSecurityInstance(SecurityInfo.PBE_WITH_SHA512_AND_AES_256)),

;

private final String decryptType;

private final String decryptInformation;
private final SecurityInfo securityInfo;

private final SecurityInstance decryptInstance;

SecurityMethod(String decryptType, String decryptInformation, SecurityInstance securityInstance) {
this.decryptType = decryptType;
this.decryptInformation = decryptInformation;
SecurityMethod(SecurityInfo securityInfo, SecurityInstance securityInstance) {
this.securityInfo = securityInfo;
this.decryptInstance = securityInstance;
}

public String decryptType() {
return decryptType;
public static SecurityMethod decryptMethod(String decryptType, String decryptInformation) {
for (SecurityMethod securityMethod : SecurityMethod.values()) {
if (securityMethod.securityInfo.decryptInformation().equals(decryptInformation)
&& securityMethod.securityInfo.decryptType().equals(decryptType))
return securityMethod;
}
return null;
}

public String decryptInformation() {
return decryptInformation;
public String decryptType() {
return securityInfo.decryptType();
}

public SecurityInstance decryptInstance() {
return decryptInstance;
}

public static SecurityMethod decryptMethod(String decryptType, String decryptInformation) {
for (SecurityMethod securityMethod : SecurityMethod.values()) {
if(securityMethod.decryptInformation.equals(decryptInformation)
&& securityMethod.decryptType.equals(decryptType))
return securityMethod;
}
return null;
public String decryptInformation() {
return securityInfo.decryptInformation();
}

public static Map<String, List<String>> getType2Information(){
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tech/shiker/config/EncToolComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public EncToolComponent() {
JLabel decryptedIvLabel = new JBLabel("Enter decrypted iv:");
JLabel decryptedSaltLabel = new JBLabel("Enter decrypted salt:");
JLabel decryptedStepLabel = new JBLabel("Enter decrypted iteration count:");
SecurityMethod.getType2Information().keySet().forEach(decryptedTypeBox::addItem);
SecurityMethod.getType2Information().keySet().stream().sorted().forEach(decryptedTypeBox::addItem);
myMainPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(new JBLabel("Html compare view:"), isHtmlView, 1, false)
.addLabeledComponent(new JBLabel("Enter decrypted type: "), decryptedTypeBox, 1, false)
Expand Down Expand Up @@ -92,7 +92,7 @@ private void updateDecryptedSalt(JBTextField decryptedSalt, JLabel decryptedSalt

// 更新城市ComboBox的内容
private void updateInformationComboBox(String decryptedType, ComboBox<String> decryptedInformationBox) {
String[] decryptedInformationArr = SecurityMethod.getType2Information().get(decryptedType).toArray(new String[0]);
String[] decryptedInformationArr = SecurityMethod.getType2Information().get(decryptedType).stream().sorted().toArray(String[]::new);
decryptedInformationBox.setModel(new DefaultComboBoxModel<>(decryptedInformationArr));
decryptedInformationBox.setSelectedItem(decryptedInformationArr[0]);
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 42f4951

Please sign in to comment.