import com.sap.it.api.ITApi
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.*;
import com.sap.it.api.keystore.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.ArrayList
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.HashMap;
import javax.net.ssl.KeyManager;
def String Hashing(String arg1){
def body = arg1;
String password;
def service = ITApiFactory.getApi(SecureStoreService.class, null);
def credential = service.getUserCredential("Security_Material");
if (credential == null)
{ throw new IllegalStateException("No credential found for alias 'Security_Material'");
}
else{
password= new String(credential.getPassword());
}
key = password.getBytes("UTF-8");
sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key = Arrays.copyOf(key, 16);
secretKey = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
def encryptedData = Base64.getEncoder().encodeToString(cipher.doFinal(body.getBytes("UTF-8")));
return encryptedData;
}
import com.sap.it.api.ITApi
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.*;
import com.sap.it.api.keystore.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.ArrayList
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.HashMap;
import javax.net.ssl.KeyManager;
def String Decrypt(String arg1){
def body = arg1;
String password;
def service = ITApiFactory.getApi(SecureStoreService.class, null);
def credential = service.getUserCredential("Security_Material");
if (credential == null)
{ throw new IllegalStateException("No credential found for alias 'Security_Material'");
}
else{
password= new String(credential.getPassword());
}
key = password.getBytes("UTF-8");
sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key = Arrays.copyOf(key, 16);
secretKey = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
def decryptedData = new String (cipher.doFinal(Base64.getDecoder().decode(body)));
return decryptedData;
}
!!!!! HaPpY LeArNiNg !!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |