Commit f4ffd61a authored by Lakshay Thakur's avatar Lakshay Thakur
Browse files

updated for supporting custom key store.

parent 5ab50cfc
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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);
+5 −0
Original line number Diff line number Diff line
@@ -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.");
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ public interface LeegalityKeyStoreBuilder {

    LeegalityKeyStoreBuilder storePassword(String var1);

    LeegalityKeyStoreBuilder keyStore(String keyStoreType);

    LeegalityKeyStore build();
}
+23 −0
Original line number Diff line number Diff line
@@ -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 {
@@ -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();
//    }
@@ -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();