Cybersecurity
DevOps Cloud (ADM)
IT Operations Cloud
function generateKey(keyValue, ALGO) {
var key = new Packages.javax.crypto.spec.SecretKeySpec(keyValue, ALGO);
return key;
}
function makeBytes(keyValue) {
var bytes = [];
for (var i = 0; i < keyValue.length; i) {
bytes.push(keyValue.charCodeAt(i));
}
return(bytes);
}
function encrypt(Data, keyValue) {
var keyValue = makeBytes(keyValue);
var ALGO = "AES";
var key = generateKey(keyValue,ALGO);
var c = new Packages.javax.crypto.Cipher.getInstance(ALGO);
c.init(Packages.javax.crypto.Cipher.ENCRYPT_MODE, key);
var encVal = c.doFinal(makeBytes(Data));
var encryptedValue = new Packages.sun.misc.BASE64Encoder().encode(encVal);
return encryptedValue;
}
function decrypt(encryptedData, keyValue) {
var keyValue = makeBytes(keyValue);
var ALGO = "AES";
var key = generateKey(keyValue,ALGO);
var c = new Packages.javax.crypto.Cipher.getInstance(ALGO);
c.init(Packages.javax.crypto.Cipher.DECRYPT_MODE, key);
var decodedValue = new Packages.sun.misc.BASE64Decoder().decodeBuffer(encryptedData);
var decValue = c.doFinal(decodedValue);
var decryptedValue = new java.lang.String(decValue);
return decryptedValue;
}
<do-set-local-variable notrace="true" name="encrypted_string">
<arg-string>
<token-xpath expression="myNameSpace:retrieveMyEncryptedString()"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="mykey" notrace="true" scope="policy">
<arg-string>
<token-named-password name="mySecretKey"/>
</arg-string>
</do-set-local-variable>
<do-set-src-password class-name="User" notrace="true">
<arg-string>
<token-xpath expression="es:decrypt($encrypted_string, $mykey)"/>
</arg-string>
</do-set-src-password>
Top Comments