Delete src/com/belkast/soap/secretProcessor.java

This commit is contained in:
Keith Armstrong 2025-01-10 00:23:11 +00:00
parent 3abd5906c1
commit 9033d81938

View File

@ -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;
}
}