From affa7dfa07fe6b421d2d644052ff00818d3af631 Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Tue, 24 Dec 2024 16:32:11 +0000 Subject: [PATCH] Added new file. --- src/com/belkast/soap/secretProcessor.java | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/com/belkast/soap/secretProcessor.java diff --git a/src/com/belkast/soap/secretProcessor.java b/src/com/belkast/soap/secretProcessor.java new file mode 100644 index 0000000..f09ac45 --- /dev/null +++ b/src/com/belkast/soap/secretProcessor.java @@ -0,0 +1,50 @@ +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