Loading src/main/java/com/leegality/encryptionDecryptionUtil/crypto/Decrypt.java +9 −2 Original line number Diff line number Diff line Loading @@ -17,10 +17,17 @@ public class Decrypt { private final String algorithm = "AES/CBC/PKCS5Padding"; public EncryptDecryptResponseVO decrypt(String payload, String salt, String pfxFilePath, String password) throws IOException, GeneralSecurityException { public EncryptDecryptResponseVO decrypt(String payload, String salt, String pfxFilePath, String password, String keyStoreType) throws IOException, GeneralSecurityException { pfxFilePath = System.getProperty("user.dir") + pfxFilePath; PrivateKey privateKey = SignatureUtil.getPrivateKey(pfxFilePath, password); PrivateKey privateKey; if (keyStoreType != null) { privateKey = SignatureUtil.getPrivateKey(pfxFilePath, password, keyStoreType); } else { privateKey = SignatureUtil.getPrivateKey(pfxFilePath, password); } String key = EncryptionUtil.decrypt(salt, privateKey); byte[] keyByte = Base64.getDecoder().decode(key); Loading src/main/java/com/leegality/encryptionDecryptionUtil/keystore/DefaultKeyStoreBuilder.java +5 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,11 @@ final class DefaultKeyStoreBuilder implements LeegalityKeyStoreBuilder { return this; } @Override public LeegalityKeyStoreBuilder keyStore(String keyStoreType) { this.keyStoreType = keyStoreType; return this; } @Override public LeegalityKeyStore build() { Objects.requireNonNull(this.inputStream, "KeyStore location is missing."); Loading src/main/java/com/leegality/encryptionDecryptionUtil/keystore/LeegalityKeyStoreBuilder.java +2 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ public interface LeegalityKeyStoreBuilder { LeegalityKeyStoreBuilder storePassword(String var1); LeegalityKeyStoreBuilder keyStore(String keyStoreType); LeegalityKeyStore build(); } src/main/java/com/leegality/encryptionDecryptionUtil/util/SignatureUtil.java +23 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,14 @@ public class SignatureUtil { .build(); } private static LeegalityKeyStore buildKeyStore(InputStream source, String password, String keyStoreType) { return LeegalityKeyStore.builder() .stream(source) .storePassword(password) .keyStore(keyStoreType) .build(); } public static LeegalityKeyStore buildKeyStore(String source, String password) { InputStream inputStream = null; try { Loading @@ -37,6 +45,16 @@ public class SignatureUtil { return buildKeyStore(inputStream, password); } public static LeegalityKeyStore buildKeyStore(String source, String password, String keyStoreType) { InputStream inputStream = null; try { inputStream = new FileInputStream(source); } catch (FileNotFoundException e) { throw new RuntimeException(e); } return buildKeyStore(inputStream, password, keyStoreType); } // public static InputStream stringToInputStream(String pfxData) { // return new ByteArrayInputStream(); // } Loading @@ -51,6 +69,11 @@ public class SignatureUtil { return leegalityKeyStore.getPrivateKey(); } public static PrivateKey getPrivateKey(String source, String password, String keyStoreType) { LeegalityKeyStore leegalityKeyStore = buildKeyStore(source, password,keyStoreType); return leegalityKeyStore.getPrivateKey(); } public static X509Certificate getCertificate(String source, String password) { LeegalityKeyStore leegalityKeyStore = buildKeyStore(source, password); return leegalityKeyStore.getX509Certificate(); Loading Loading
src/main/java/com/leegality/encryptionDecryptionUtil/crypto/Decrypt.java +9 −2 Original line number Diff line number Diff line Loading @@ -17,10 +17,17 @@ public class Decrypt { private final String algorithm = "AES/CBC/PKCS5Padding"; public EncryptDecryptResponseVO decrypt(String payload, String salt, String pfxFilePath, String password) throws IOException, GeneralSecurityException { public EncryptDecryptResponseVO decrypt(String payload, String salt, String pfxFilePath, String password, String keyStoreType) throws IOException, GeneralSecurityException { pfxFilePath = System.getProperty("user.dir") + pfxFilePath; PrivateKey privateKey = SignatureUtil.getPrivateKey(pfxFilePath, password); PrivateKey privateKey; if (keyStoreType != null) { privateKey = SignatureUtil.getPrivateKey(pfxFilePath, password, keyStoreType); } else { privateKey = SignatureUtil.getPrivateKey(pfxFilePath, password); } String key = EncryptionUtil.decrypt(salt, privateKey); byte[] keyByte = Base64.getDecoder().decode(key); Loading
src/main/java/com/leegality/encryptionDecryptionUtil/keystore/DefaultKeyStoreBuilder.java +5 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,11 @@ final class DefaultKeyStoreBuilder implements LeegalityKeyStoreBuilder { return this; } @Override public LeegalityKeyStoreBuilder keyStore(String keyStoreType) { this.keyStoreType = keyStoreType; return this; } @Override public LeegalityKeyStore build() { Objects.requireNonNull(this.inputStream, "KeyStore location is missing."); Loading
src/main/java/com/leegality/encryptionDecryptionUtil/keystore/LeegalityKeyStoreBuilder.java +2 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ public interface LeegalityKeyStoreBuilder { LeegalityKeyStoreBuilder storePassword(String var1); LeegalityKeyStoreBuilder keyStore(String keyStoreType); LeegalityKeyStore build(); }
src/main/java/com/leegality/encryptionDecryptionUtil/util/SignatureUtil.java +23 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,14 @@ public class SignatureUtil { .build(); } private static LeegalityKeyStore buildKeyStore(InputStream source, String password, String keyStoreType) { return LeegalityKeyStore.builder() .stream(source) .storePassword(password) .keyStore(keyStoreType) .build(); } public static LeegalityKeyStore buildKeyStore(String source, String password) { InputStream inputStream = null; try { Loading @@ -37,6 +45,16 @@ public class SignatureUtil { return buildKeyStore(inputStream, password); } public static LeegalityKeyStore buildKeyStore(String source, String password, String keyStoreType) { InputStream inputStream = null; try { inputStream = new FileInputStream(source); } catch (FileNotFoundException e) { throw new RuntimeException(e); } return buildKeyStore(inputStream, password, keyStoreType); } // public static InputStream stringToInputStream(String pfxData) { // return new ByteArrayInputStream(); // } Loading @@ -51,6 +69,11 @@ public class SignatureUtil { return leegalityKeyStore.getPrivateKey(); } public static PrivateKey getPrivateKey(String source, String password, String keyStoreType) { LeegalityKeyStore leegalityKeyStore = buildKeyStore(source, password,keyStoreType); return leegalityKeyStore.getPrivateKey(); } public static X509Certificate getCertificate(String source, String password) { LeegalityKeyStore leegalityKeyStore = buildKeyStore(source, password); return leegalityKeyStore.getX509Certificate(); Loading