From 19554a6acf91cf3f10ac07375076c6c20c4a4b2c Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Fri, 10 Jan 2025 00:22:31 +0000 Subject: [PATCH 1/3] Renamed the class, and therefore orphaned --- src/com/belkast/soap/salter.java | 79 -------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 src/com/belkast/soap/salter.java diff --git a/src/com/belkast/soap/salter.java b/src/com/belkast/soap/salter.java deleted file mode 100644 index c0bf75c..0000000 --- a/src/com/belkast/soap/salter.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.belkast.soap; - -import javax.crypto.*; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.PBEKeySpec; -import javax.crypto.spec.SecretKeySpec; -import java.io.UnsupportedEncodingException; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.KeySpec; -import java.util.Base64; - -public class salter { - - private static final int KEY_LENGTH = 256; - private static final int ITERATION_COUNT = 65536; - - public static String encrypt(String strToEncrypt, String secretKey, String salt) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeySpecException, BadPaddingException, InvalidKeyException { - - try { - - SecureRandom secureRandom = new SecureRandom(); - byte[] iv = new byte[16]; - secureRandom.nextBytes(iv); - IvParameterSpec ivspec = new IvParameterSpec(iv); - - SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); - KeySpec spec = new PBEKeySpec(secretKey.toCharArray(), salt.getBytes(), ITERATION_COUNT, KEY_LENGTH); - SecretKey tmp = factory.generateSecret(spec); - SecretKeySpec secretKeySpec = new SecretKeySpec(tmp.getEncoded(), "AES"); - - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivspec); - - byte[] cipherText = cipher.doFinal(strToEncrypt.getBytes("UTF-8")); - byte[] encryptedData = new byte[iv.length + cipherText.length]; - System.arraycopy(iv, 0, encryptedData, 0, iv.length); - System.arraycopy(cipherText, 0, encryptedData, iv.length, cipherText.length); - - return Base64.getEncoder().encodeToString(encryptedData); - } catch (Exception e) { - throw e; - } - } - - public static String decrypt(String strToDecrypt, String secretKey, String salt) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, UnsupportedEncodingException, BadPaddingException, NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException { - - try { - if (strToDecrypt == null) - { - return null; - } - - byte[] encryptedData = Base64.getDecoder().decode(strToDecrypt); - byte[] iv = new byte[16]; - System.arraycopy(encryptedData, 0, iv, 0, iv.length); - IvParameterSpec ivspec = new IvParameterSpec(iv); - - SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); - KeySpec spec = new PBEKeySpec(secretKey.toCharArray(), salt.getBytes(), ITERATION_COUNT, KEY_LENGTH); - SecretKey tmp = factory.generateSecret(spec); - SecretKeySpec secretKeySpec = new SecretKeySpec(tmp.getEncoded(), "AES"); - - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivspec); - - byte[] cipherText = new byte[encryptedData.length - 16]; - System.arraycopy(encryptedData, 16, cipherText, 0, cipherText.length); - - byte[] decryptedText = cipher.doFinal(cipherText); - return new String(decryptedText, "UTF-8"); - } catch (Exception e) { - throw e; - } - } -} \ No newline at end of file From 3abd5906c1d5f372562c5172a31bb8ec3d647127 Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Fri, 10 Jan 2025 00:22:54 +0000 Subject: [PATCH 2/3] Renamed the class, and therefore orphaned --- src/com/belkast/soap/userCreds.java | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/com/belkast/soap/userCreds.java diff --git a/src/com/belkast/soap/userCreds.java b/src/com/belkast/soap/userCreds.java deleted file mode 100644 index 3e00553..0000000 --- a/src/com/belkast/soap/userCreds.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.belkast.soap; - -import java.io.Console; -import java.util.*; - -public class userCreds { - public static String getUsername(String thisPrompt) { - Scanner myObj = new Scanner(System.in); - System.out.print(thisPrompt); - String varEntry; - varEntry = myObj.nextLine(); - return varEntry; - } - - public static char[] getPassword(String thisPrompt) { - Console console = System.console(); - char[] password = console.readPassword(thisPrompt); - return password; - } -} \ No newline at end of file From 9033d819383c93a3a3d87ca90947e0e873a5ce99 Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Fri, 10 Jan 2025 00:23:11 +0000 Subject: [PATCH 3/3] Delete src/com/belkast/soap/secretProcessor.java --- src/com/belkast/soap/secretProcessor.java | 50 ----------------------- 1 file changed, 50 deletions(-) delete mode 100644 src/com/belkast/soap/secretProcessor.java diff --git a/src/com/belkast/soap/secretProcessor.java b/src/com/belkast/soap/secretProcessor.java deleted file mode 100644 index f09ac45..0000000 --- a/src/com/belkast/soap/secretProcessor.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.belkast.soap; - -import java.util.Base64; -import java.security.Key; -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; - -public class secretProcessor - { - private static final String ALGORITHM = "AES"; - - public static byte[] encrypt(String thisKey, String valueToEnc) throws Exception - { - byte[] varKey = thisKey.getBytes(); - Key key = generateKey(varKey); - Cipher c = Cipher.getInstance(ALGORITHM); - c.init(1, key); - byte[] encValue = c.doFinal(valueToEnc.getBytes()); - return encValue; - } - - public static String decrypt(String thisKey, byte[] encryptedValue) throws Exception - { - byte[] varKey = thisKey.getBytes(); - Key key = generateKey(varKey); - Cipher c = Cipher.getInstance(ALGORITHM); - c.init(2, key); - byte[] decValue = c.doFinal(encryptedValue); - String decryptedValue = new String(decValue); - return decryptedValue; - } - - public static String encode(byte[] value) throws Exception - { - String encryptedValue = Base64.getEncoder().encodeToString(value); - return encryptedValue; - } - - public static byte[] decode(String encryptedValue) throws Exception - { - byte[] decordedValue = Base64.getDecoder().decode(encryptedValue); - return decordedValue; - } - - private static Key generateKey(byte[] varKey) throws Exception - { - Key key = new SecretKeySpec(varKey, "AES"); - return key; - } - } \ No newline at end of file